﻿-- #################################################################################################################
-- Variables
-- #################################################################################################################
-- -----------------------------------------------------------------------------------------------------------------
SLASH_XBAR1="/xbar";
SlashCmdList["XBAR"]=function(editBox,msg) XBar_SlashHandler(msg); end
-- -----------------------------------------------------------------------------------------------------------------
XBar={};
XLng={};
_G["XBAR"]="XBar III v1.32";
local version="v1.32";
local loc=GetLocation(); if (loc~="DE") and (loc~="TW") then loc="EN"; end
local obj=DEFAULT_CHAT_FRAME;
local orig=obj["AddMessage"];
local spamindex=nil;
local updatetimer=0;
local xpage={
        "Info","G","B","X",
        "B_Ammo","B_Bag","B_Clock","B_Dps","B_Exp","B_Friend","B_Guild","B_Klass","B_Mail","B_Money","B_Ping",
        "X_PF","X_TF","X_TT","X_BF","X_DB","X_CB","X_XP","X_PT","X_RF","X_MF","X_HF",
};
local xbtns={"Ammo","Bag","Clock","Dps","Exp","Friend","Guild","Klass","Mail","Money","Ping"};
local mbtns={"CfgBtn","SysBtn","DspBtn","SndBtn","TbkBtn"};
local mdsgn={"Default","Antz","Round","Square","Archlord","Gloss","Dark","Wings","Diamond","Hexagon","Nexus"};
local xdsgn={"Blockz","Black","Blue","AdPanel","Gloss"};
local XBar_default={
        ["PlayedDays"]=0,["PlayedHour"]=0,["PlayedMins"]=0,
        ["Enable"]=true,["Menu"]=false,["Alpha"]=0.60,["Scale"]=1.0,["Position"]="BOTTOM",["Style"]=4,["Lng"]=loc,
        ["MainMenuFrame"]=true,["ExperienceFrame"]=false,["EquipDameFrame"]=true,
        ["Afk"]=0,["AfkEnable"]=true,["AfkKeepMsg"]=true,["AfkMind"]=true,["AfkAuto"]=false,["AfkTimer"]=600,
                ["AfkMsg"]={[1]={["date"]="04.Jul 1976",["time"]="07:00.00",["text"]="This is a test message.",["name"]="Animae"}},
                ["AfkLogo_X"]=600,["AfkLogo_Y"]=76,["AfkMsg_X"]=500,["AfkMsg_Y"]=100,
                ["AfkV1"]="<AFK> im currently away from keyboard.",
                ["AfkV2"]="<DND> please do not disturb.",
        ["Ammo"]=false,["Ammo_X"]=875,
                ["AmmoT1"]=true,["AmmoV1"]="[AMMO]",
                ["AmmoT2"]=false,["AmmoV2"]="",
        ["Bag"]=true,["Bag_X"]=273,
                ["BagT1"]=true,["BagV1"]="Slots: [USED] / [TOTAL]",
                ["BagT2"]=true,["BagV2"]="Used: [LOAD] %",
        ["Clock"]=true,["Clock_X"]=741,
                ["ClockT1"]=true,["ClockV1"]="Time: [TIME24] Uhr",["ClockV2"]="Time: [TIME12]",["ClockV3"]="Date: [DATE]",
                ["ClockT2"]=true,["ClockV4"]="Total: [TOTALONLINE]",["ClockV5"]="Game: [ONLINE]",
        ["Dps"]=true,["Dps_X"]=561,
                ["DpsT1"]=true,["DpsV1"]="DPS: [DPS]",
                ["DpsT2"]=true,["DpsV2"]="DMG: [DMG]",
        ["Exp"]=true,["Exp_X"]=155,
                ["ExpT1"]=true,["ExpV1"]="TP: [TP]",
                ["ExpT2"]=true,["ExpV2"]="XP: [PERCENT]",
        ["Friend"]=true,["Friend_X"]=695,
                ["FriendT1"]=false,["FriendV1"]="[ONLINE]",
                ["FriendT2"]=false,["FriendV2"]="[COUNT]",
        ["Guild"]=true,["Guild_X"]=661,
                ["GuildT1"]=false,["GuildV1"]="[GNAME]",
                ["GuildT2"]=false,["GuildV2"]="[ONLINE]",
        ["Klass"]=true,["Klass_X"]=107,
                ["KlassT1"]=false,["KlassV1"]="[MCLASS]：[MLVL]",
                ["KlassT2"]=false,["KlassV2"]="[SCLASS]：[SLVL]",
        ["Mail"]=false,["Mail_X"]=960,
                ["MailT1"]=false,["MailV1"]="New：[UNREAD]",
                ["MailT2"]=false,["MailV2"]="",
        ["Money"]=true,["Money_X"]=421,
                ["MoneyT1"]=true,["MoneyV1"]="Gold: [GOLD]",
                ["MoneyT2"]=true,["MoneyV2"]="Dias: [DIAS]",
        ["Ping"]=true,["Ping_X"]=906,
                ["PingT1"]=true,["PingV1"]="ms: [MS]",
                ["PingT2"]=true,["PingV2"]="Fps: [FPS]",
        ["Spam"]=true,["Spamlist"]={"talentpunkte"," experience points"," erfahrungspunkte","you got","you'll get","ihr bekommt","someone has opened an auction interface","you give up","very cheap","magic gold","cheap gold","best service","instant delivery","www . l e v e l n . de","delivery in","www.rmt4game.com","lowest price","www. leveln .de"},
        ["PF"]=false,["PF_X"]=0,["PF_Y"]=32,["PF_Anchor"]=false,
        ["TF"]=false,["TF_X"]=392,["TF_Y"]=32,["TF_Anchor"]=false,
        ["TT"]=false,["TT_X"]=540,["TT_Y"]=80,["TT_Anchor"]=false,
        ["BF"]=false,["BF_X"]=600,["BF_Y"]=32,["BF_Anchor"]=false,
        ["DB"]=false,["DB_X"]=600,["DB_Y"]=55,["DB_Anchor"]=false,
        ["CB"]=false,["CB_X"]=600,["CB_Y"]=55,["CB_Anchor"]=false,
        ["XP"]=true,["XP_Xs"]=100,["XP_Ys"]=0,["XP_Anchor"]=false,
                ["XP_Xe"]=-100,["XP_Ye"]=0,["XP_H"]=13,
        ["PT"]=false,["PT_X"]=0,["PT_Y"]=100,["PT_Anchor"]=false,
        ["RF"]=false,["RF_X"]=15,["RF_Y"]=120,["RF_Anchor"]=false,
        ["MF"]=true,["MF_X"]=835,["MF_Y"]=13,["MF_Anchor"]=false,
                ["MF_Double"]=false,["MF_Style"]=3,["MF_Size"]=190,["MF_Buttons"]=true,
        ["MF_Time"]=true,["MF_Time_X"]=805,["MF_Time_Y"]=170,["MF_Time_Anchor"]=false,
        ["MF_Title"]=false,["MF_Title_X"]=690,["MF_Title_Y"]=32,["MF_Title_Anchor"]=false,
        ["HF"]=true,["HF_X"]=0,["HF_Y"]=32,["HF_Anchor"]=false,
        ["CF"]=false,["CF_X"]=0,["CF_Y"]=500,["CF_Anchor"]=false,
        ["EQDmg_Scale"]=1,["EQDmg_X"]=-1,["EQDmg_Y"]=-1,
};
XAddons={
-- [[ beginn
--        {
--                name="Game Settings",children=true,title="Game Settings",version="0.1",
--                type="TopMenu",
--                window="XBarGameCfg_Info",
--                OnClick=function() XBarGameCfg:Show(); end,
--        },{
--                name="Volume",title="Game Settings - Volume",
--                type="ItemBtn",
--                window="XBarGameCfg_Info",
--                OnClick=function() XBarGameCfg:Show(); end,
--        },{
--                name="Graphic",title="Game Settings - Graphic",
--                type="ItemBtn",
--                window="XBarGameCfg_Info",
--                OnClick=function() XBarCfg:Show(); end,
--        },{
--                name="Game Config",title="Game Settings - Game Config",
--                type="ItemBtn",
--                window="XBarGameCfg_Info",
--                OnClick=function() XBarCfg:Show(); end,
--        },{
--                name="Action Bars",title="Game Settings - Action Bars",
--                type="ItemBtn",
--                window="XBarGameCfg_Info",
--                OnClick=function() XBarCfg:Show(); end,
--        },{
--                name="Chat",title="Game Settings - Chat",
--                type="ItemBtn",
--                window="XBarGameCfg_Info",
--                OnClick=function() XBarCfg:Show(); end,
--        },{
--                name="Key Bindings",title="Game Settings - Keybindings",
--                type="ItemBtn",
--                window="XBarGameCfg_Info",
--                OnClick=function() XBarCfg:Show(); end,
--        },
-- [[ end

        {
                name="XBar",children=true,title="X Bar",version=version,
                type="TopMenu",
                window="XBarCfg_Info",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="General",children=false,title="XBar - General",
                type="SubMenu",
                window="XBarCfg_G",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="X-AfK",title="XBar - X-Afk",
                type="SubMenu",
                window="XBarCfg_Afk",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="AntiSpam",title="XBar - AntiSpam",
                type="SubMenu",
                window="XBarCfg_Spam",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Buttons",children=true,title="XBar - Buttons",
                type="SubMenu",
                window="XBarCfg_Info",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Ammo",title="XBar - Buttons - Ammo",
                type="ItemBtn",
                window="XBarCfg_B_Ammo",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Bag",title="XBar - Buttons - Bag",
                type="ItemBtn",
                window="XBarCfg_B_Bag",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Classes",title="XBar - Buttons - Classes",
                type="ItemBtn",
                window="XBarCfg_B_Klass",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Clock",title="XBar - Buttons - Clock",
                type="ItemBtn",
                window="XBarCfg_B_Clock",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="DPSMeter",title="XBar - Buttons - DPSMeter",
                type="ItemBtn",
                window="XBarCfg_B_Dps",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Experience",title="XBar - Buttons - Experience",
                type="ItemBtn",
                window="XBarCfg_B_Exp",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Friend",title="XBar - Buttons - Friend",
                type="ItemBtn",
                window="XBarCfg_B_Friend",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Guild",title="XBar - Buttons - Guild",
                type="ItemBtn",
                window="XBarCfg_B_Guild",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Mail",title="XBar - Buttons - Mail",
                type="ItemBtn",
                window="XBarCfg_B_Mail",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Money",title="XBar - Buttons - Money",
                type="ItemBtn",
                window="XBarCfg_B_Money",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Performance",title="XBar - Buttons - Performance",
                type="ItemBtn",
                window="XBarCfg_B_Ping",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="XFrames",children=true,title="XFrames",version=version,
                type="TopMenu",
                window="XBarCfg_Info",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Player",title="XFrames - PlayerFrame",
                type="ItemBtn",
                window="XBarCfg_X_PF",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Target",title="XFrames - TargetFrame",
                type="ItemBtn",
                window="XBarCfg_X_TF",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="TargetTarget",title="XFrames - TargetTargetFrame",
                type="ItemBtn",
                window="XBarCfg_X_TT",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="BuffBar",title="XFrames - BuffBar",
                type="ItemBtn",
                window="XBarCfg_X_BF",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="DebuffBar",title="XFrames - DebuffBar",
                type="ItemBtn",
                window="XBarCfg_X_DB",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="CastingBar",title="XFrames - CastingBar",
                type="ItemBtn",
                window="XBarCfg_X_CB",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Experience",title="XFrames - ExperienceFrame",
                type="ItemBtn",
                window="XBarCfg_X_XP",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Party",title="XFrames - PartyMemberFrame",
                type="ItemBtn",
                window="XBarCfg_X_PT",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Raid",title="XFrames - RaidPartyFrame",
                type="ItemBtn",
                window="XBarCfg_X_RF",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Minimap",title="XFrames - MinimapFrame",
                type="ItemBtn",
                window="XBarCfg_X_MF",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="House",title="XFrames - HouseFrame",
                type="ItemBtn",
                window="XBarCfg_X_HF",
                OnClick=function() XBarCfg:Show(); end,
        },{
                name="Chat 1",title="XFrames - ChatFrame",
                type="ItemBtn",
                window="XBarCfg_X_CF",
                OnClick=function() XBarCfg:Show(); end,
        }
};
local XBarMainButtons={
        {
                icon="Interface\\Minimap\\MinimapButton_BattleGround_Normal",
    GetText=function() return XLng["PopupBtn"]["Main_BG1"]; end,
    GetTooltip=function() return XLng["PopupBtn"]["Main_BG2"]; end,
    OnClick=function() ToggleUIFrame(BattleGroundQueueFrame); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-SortBoard",
                GetText=function() return XLng["PopupBtn"]["Main_SB1"]; end,
                GetTooltip=function() return XLng["PopupBtn"]["Main_SB2"]; end,
                OnClick=function() ToggleUIFrame(getglobal("SortScoreBoard")); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-SuitSkill",
                GetText=function() return XLng["PopupBtn"]["Main_KF1"]; end,
                GetTooltip=function() return XLng["PopupBtn"]["Main_KF2"]; end,
                OnClick=function() ToggleUIFrame(getglobal("SkillSuitFrame")); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Card",
                GetText=function() return XLng["PopupBtn"]["Main_MC1"]; end,
                GetTooltip=function() return XLng["PopupBtn"]["Main_MC2"]; end,
                OnClick=function() ToggleUIFrame(getglobal("CardBookFrame")); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Character",
                GetText=function() return XLng["PopupBtn"]["Main_CF1"]; end,
                GetTooltip=function() return XLng["PopupBtn"]["Main_CF2"]; end,
                OnClick=function() ToggleCharacter("EquipmentFrame"); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Skill",
                GetText=function() return XLng["PopupBtn"]["Main_SF1"]; end,
                GetTooltip=function() return XLng["PopupBtn"]["Main_SF2"]; end,
                OnClick=function() ToggleUIFrame(getglobal("UI_SkillBook")); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Quest",
                GetText=function() return XLng["PopupBtn"]["Main_QF1"]; end,
                GetTooltip=function() return XLng["PopupBtn"]["Main_QF2"]; end,
                OnClick=function() ToggleUIFrame(getglobal("UI_QuestBook")); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Quild",
                GetText=function() return XLng["PopupBtn"]["Main_GF1"]; end,
                GetTooltip=function() return XLng["PopupBtn"]["Main_GF2"]; end,
                OnClick=function() ToggleUIFrame(getglobal("GuildFrame")); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Contacts",
                GetText=function() return XLng["PopupBtn"]["Main_FL1"]; end,
                GetTooltip=function() return XLng["PopupBtn"]["Main_FL2"]; end,
                OnClick=function() ToggleSocialFrame("Friend"); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Clock",
                GetText=function() return "|cffFCFC76"..TIMEFLAG_TITLE; end,
                GetTooltip=function() return TIMEFLAG_TIP; end,
                OnClick=function() TimeFlagFrame:Show(); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Bank",
                GetText=function()
                        if (TimeLet_GetLetTime("BankLet")>=0) then return "|cffCFCF76  "..TIMEFLAG_HANDY_BANK;
                        else return "  |cff808080"..TIMEFLAG_HANDY_BANK; end
                end,
                GetTooltip=function() return TIMEFLAG_HANDY_BANK_TIP; end,
                OnClick=function()
                        if (TimeLet_GetLetTime("BankLet")<0) then StaticPopup_Show("TIMEFLAG_FAIL1"); return;
                        else OpenBank(); end
                end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Auction",
                GetText=function()
                        if (TimeLet_GetLetTime("AuctionLet")>=0) then return "  |cffFCFC76"..TIMEFLAG_HANDY_AUCTION;
                        else return "  |cff808080"..TIMEFLAG_HANDY_AUCTION; end
                end,
                GetTooltip=function() return TIMEFLAG_HANDY_AUCTION_TIP; end,
                OnClick=function()
                        if (TimeLet_GetLetTime("AuctionLet")<0) then StaticPopup_Show("TIMEFLAG_FAIL1"); return;
                        else OpenAuction(); end
                end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Mail",
                GetText=function()
                        if (TimeLet_GetLetTime("MailLet")>=0) then return "  |cffFCFC76"..TIMEFLAG_HANDY_MAIL;
                        else return "  |cff808080"..TIMEFLAG_HANDY_MAIL; end
                end,
                GetTooltip=function() return TIMEFLAG_HANDY_MAIL_TIP; end,
                OnClick = function()
                        if (TimeLet_GetLetTime("MailLet")<0) then StaticPopup_Show("TIMEFLAG_FAIL1"); return;
                        else OpenMail(); end
                end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Beauty",
                GetText=function() return XLng["PopupBtn"]["Main_SS1"]; end,
                GetTooltip=function() return XLng["PopupBtn"]["Main_SS2"]; end,
                OnClick=function() ToggleUIFrame(BeautyStudioFrame); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Merchant",
                GetText=function() return XLng["PopupBtn"]["Main_IS1"]; end,
                GetTooltip=function() return XLng["PopupBtn"]["Main_IS2"]; end,
                OnClick=function() ToggleUIFrame(ItemMallFrame); end
        }
};
local XBarSystemButtons={
        {
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-InstanceRecord",
                GetText=function() return XLng["PopupBtn"]["Main_IR1"]; end,
                GetTooltip=function() return XLng["PopupBtn"]["Main_IR2"]; end,
                OnClick=function() ToggleUIFrame(getglobal("InstanceRecordFrame")); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Sys_AS1"]; end,
                OnClick=function() ShowUIPanel(SYS_AudioSettings_Frame); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Sys_GC1"]; end,
                OnClick=function() HideUIPanel(GameMenuFrame); ShowUIPanel(GameConfigFrame); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Sys_KB1"]; end,
                OnClick=function() ShowUIPanel(KeyDefineFrame); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Sys_ME1"]; end,
                OnClick=function() HideUIPanel(GameMenuFrame); ShowUIPanel(MacroFrame); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Sys_GH1"]; end,
                OnClick=function() HideUIPanel(GameMenuFrame); ShowUIPanel(TeachingFrame); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Sys_CS1"]; end,
                OnClick=function() HideUIPanel(GameMenuFrame); ShowUIPanel(GmNotificationFrame); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Sys_SC1"]; end,
                OnClick=function() HideUIPanel(GameMenuFrame); Logout(); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Close",
                GetText=function() return "|cffFFC7C7"..XLng["PopupBtn"]["Sys_SM1"]; end,
                OnClick=function() HideUIPanel(GameMenuFrame); StaticPopup_Show("QUIT"); end
        }
};
local XBarBonusButtons={
        {
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Bon_Ba1"]; end,
                GetTooltip=function() return XLng["PopupBtn"]["Bon_Ba2"]; end,
                OnClick=function() ShowUIPanel(NotepadFrame); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Bon_Bu4"]; end,
                OnClick=function() ShowUIPanel(CopyChatFrame); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Bon_Bu8"]; end,
                OnClick=function() PartyMemMemmo(); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Bon_Bu9"]; end,
                OnClick=function() PartyReInvite(); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Bon_Bu5"]; end,
                OnClick=function() ShowUIPanel(guiCalcFrame); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Bon_Bu6"]; end,
                OnClick=function() KillStatsPanelFrame:Show(); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Bon_Bu1"]; end,
                OnClick=function() switch1(); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Bon_Bu2"]; end,
                OnClick=function() previewit(); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Bon_Bu3"]; end,
                OnClick=function() IBF_NoMSG(); end
        },{
                icon="Interface\\MainMenuFrame\\MainPopupButton-Icon-Crafting",
                GetText=function() return XLng["PopupBtn"]["Bon_Bu7"]; end,
                OnClick=function() MacroInfo(); end
        }
};
-- #################################################################################################################
-- Events
-- #################################################################################################################
function XBar_OnLoad(this)
        this:RegisterEvent("VARIABLES_LOADED");
        SaveVariables("XBar");
end

function XBar_OnUpdate()
        if (XBar["Enable"]==true) then
                if (XBar["MainMenuFrame"]==true) then MainMenuFrame:Hide(); else MainMenuFrame:Show(); end
                if (XBar["ExperienceFrame"]==true) then ExperienceFrame:Hide(); else ExperienceFrame:Show(); end
                if (XBar["EquipDameFrame"]==true) then EquipDameFrame:Hide(); end
        end
end

function XBar_OnEvent(this,event,xload)
        if (event=="VARIABLES_LOADED") then
                local scale=GetUIScale();
                if (type(XBar)~="table") then XBar=XBar_default;
                else for i,v in pairs(XBar_default) do if (type(XBar[i])=="nil") then XBar[i]=v; end; end; end
                XLng=XBar_LoadFile("Interface/Addons/XBar/Lng/XBar."..loc..".lua") or {};
                if (XBar["Enable"]==false) then
                        XBarFrame:Hide(); XBarCfgBtn:Hide();
                        XBarSysBtn:Hide(); XBarDspBtn:Hide(); XBarSndBtn:Hide(); XBarTbkBtn:Hide();
                        for i,v in pairs(xbtns) do getglobal("XBar"..v):Hide(); getglobal("XBar"..v.."_F"):Hide(); getglobal("XBar"..v.."_B"):Hide(); end
                elseif (XBar["Enable"]==true) then
                        XBarFrame:SetAlpha(XBar["Alpha"]);
                        XBarFrame:Show(); XBarCfgBtn:Show();
                        XBarSysBtn:Show(); XBarDspBtn:Show(); XBarSndBtn:Show(); XBarTbkBtn:Show();
                        for i,v in pairs(xbtns) do getglobal("XBar"..v):Show(); getglobal("XBar"..v.."_F"):Show(); getglobal("XBar"..v.."_B"):Show(); end
                        if (XBar["Position"]=="TOP") then
                                XBarFrame:ClearAllAnchors();
                                XBarFrame:SetAnchor("TOPLEFT","TOPLEFT","UIParent",0,0);
                                XBarFrame:SetAnchor("TOPRIGHT","TOPRIGHT","UIParent",0,0);
                                getglobal("XBarFrame_BgndL"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\Bar_BgndL.tga");
                                getglobal("XBarFrame_BgndM"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\Bar_BgndM.tga");
                                getglobal("XBarFrame_BgndR"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\Bar_BgndR.tga");
                                for i,v in pairs(xbtns) do
                                        getglobal("XBar"..v.."_Bgnd"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\Bar_Btn.tga");
                                        getglobal("XBar"..v):ClearAllAnchors();
                                        getglobal("XBar"..v):SetAnchor("LEFT","LEFT","XBarFrame",XBar[v.."_X"]/scale,0);
                                        getglobal("XBar"..v.."_B"):ClearAllAnchors();
                                        getglobal("XBar"..v.."_B"):SetAnchor("LEFT","LEFT","XBar"..v,28,-1);
                                        getglobal("XBar"..v.."_F"):ClearAllAnchors();
                                        getglobal("XBar"..v.."_F"):SetAnchor("TOPLEFT","TOPLEFT","XBar"..v,64,3);
                                end
                                for i,v in pairs(mbtns) do
                                        if (v=="SndBtn" and XBar["Muted"]) then
                                                getglobal("XBar"..v.."_nTexture"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\"..v.."_Muted.tga");
                                        else
                                                getglobal("XBar"..v.."_nTexture"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\"..v.."_Normal.tga");
                                        end
                                        getglobal("XBar"..v.."_pTexture"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\"..v.."_Pushed.tga");
                                        getglobal("XBar"..v.."_hTexture"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\AllBtn_Enlight.tga");
                                end
                        elseif (XBar["Position"]=="BOTTOM") then
                                XBarFrame:ClearAllAnchors();
                                XBarFrame:SetAnchor("BOTTOMLEFT","BOTTOMLEFT","UIParent",0,0);
                                XBarFrame:SetAnchor("BOTTOMRIGHT","BOTTOMRIGHT","UIParent",0,0);
                                getglobal("XBarFrame_BgndL"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\BarU_BgndL.tga");
                                getglobal("XBarFrame_BgndM"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\BarU_BgndM.tga");
                                getglobal("XBarFrame_BgndR"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\BarU_BgndR.tga");
                                for i,v in pairs(xbtns) do
                                        getglobal("XBar"..v.."_Bgnd"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\BarU_Btn.tga");
                                        getglobal("XBar"..v):ClearAllAnchors();
                                        getglobal("XBar"..v):SetAnchor("LEFT","LEFT","XBarFrame",XBar[v.."_X"]/scale,0);
                                        getglobal("XBar"..v.."_B"):ClearAllAnchors();
                                        getglobal("XBar"..v.."_B"):SetAnchor("LEFT","LEFT","XBar"..v,28,0);
                                        getglobal("XBar"..v.."_F"):ClearAllAnchors();
                                        getglobal("XBar"..v.."_F"):SetAnchor("TOPLEFT","TOPLEFT","XBar"..v,64,5);
                                end
                                for i,v in pairs(mbtns) do
                                        if (v=="SndBtn" and XBar["Muted"]) then
                                                getglobal("XBar"..v.."_nTexture"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\"..v.."_Muted.tga");
                                        else
                                                getglobal("XBar"..v.."_nTexture"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\"..v.."_Normal.tga");
                                        end
                                        getglobal("XBar"..v.."_pTexture"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\"..v.."_Pushed.tga");
                                        getglobal("XBar"..v.."_hTexture"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\AllBtn_Enlight.tga");
                                end
                        end
                        if (XBar["Menu"]==false) then XBarSysBtn:Show(); XBarDspBtn:Hide(); XBarSndBtn:Hide(); XBarTbkBtn:Hide();
                        else XBarSysBtn:Show(); XBarDspBtn:Show(); XBarSndBtn:Show(); XBarTbkBtn:Show(); end
                        for i,v in pairs(xbtns) do
                                if (XBar[v]==false) then getglobal("XBar"..v):Hide(); getglobal("XBar"..v.."_F"):Hide(); getglobal("XBar"..v.."_B"):Hide();
                                else getglobal("XBar"..v):Show(); getglobal("XBar"..v.."_F"):Show(); getglobal("XBar"..v.."_B"):Show(); end
                        end
                end
                if (XBar["PF"]==true) then
                        if (XBar["PF_Anchor"]==true) then XFramePF:Show(); else XFramePF:Hide(); end
                        PlayerFrame:ClearAllAnchors();
                        PlayerFrame:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["PF_X"]/scale,XBar["PF_Y"]/scale);
                end
                if (XBar["TF"]==true) then
                        if (XBar["TF_Anchor"]==true) then XFrameTF:Show(); else XFrameTF:Hide(); end
                        TargetFrame:ClearAllAnchors();
                        TargetFrame:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["TF_X"]/scale,XBar["TF_Y"]/scale);
                end
                if (XBar["TT"]==true) then
                        if (XBar["TT_Anchor"]==true) then XFrameTT:Show(); else XFrameTT:Hide(); end
                        TargetTargetFrame:ClearAllAnchors();
                        TargetTargetFrame:SetAnchor("TOPLEFT","TOPLEFT","UIParent",(XBar["TT_X"])/scale,(XBar["TT_Y"])/scale);
                end
                if (XBar["BF"]==true) then
                        if (XBar["BF_Anchor"]==true) then XFrameBF:Show(); else XFrameBF:Hide(); end
                        PlayerBuffButton1:ClearAllAnchors();
                        PlayerBuffButton1:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["BF_X"]/scale,XBar["BF_Y"]/scale);
                end
                if (XBar["DB"]==true) then
                        if (XBar["DB_Anchor"]==true) then XFrameDB:Show(); else XFrameDB:Hide(); end
                        PlayerDebuffButton1:ClearAllAnchors();
                        PlayerDebuffButton1:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["DB_X"]/scale,XBar["DB_Y"]/scale);
                end
                if (XBar["CB"]==true) then
                        if (XBar["CB_Anchor"]==true) then XFrameCB:Show(); else XFrameCB:Hide(); end
                        CastingBarFrame:ClearAllAnchors();
                        CastingBarFrame:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["CB_X"]/scale,XBar["CB_Y"]/scale);
                end
                if (XBar["XP"]==true) then
                        if (XBar["XP_Anchor"]==true) then XFrameXP:Show(); else XFrameXP:Hide(); end
                        ExperienceFrame:SetSize(1,XBar["XP_H"]);
                        ExperienceFrame:ClearAllAnchors();
                        ExperienceFrame:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["XP_Xs"]/scale,XBar["XP_Ys"]/scale);
                        ExperienceFrame:SetAnchor("TOPRIGHT","TOPRIGHT","UIParent",XBar["XP_Xe"]/scale,XBar["XP_Ye"]/scale);
                end
                if (XBar["PT"]==true) then
                        if (XBar["PT_Anchor"]==true) then XFramePT:Show(); else XFramePT:Hide(); end
                        UnitFrame_party1:ClearAllAnchors();
                        UnitFrame_party1:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["PT_X"]/scale,XBar["PT_Y"]/scale);
                end
                if (XBar["RF"]==true) then
                        if (XBar["RF_Anchor"]==true) then XFrameRF:Show(); else XFrameRF:Hide(); end
                        if(g_UIPanelAnchorFrameOptions) then
                                g_UIPanelAnchorFrameOptions["RaidPartyFrame1"]={["y"]=(XBar["RF_Y"]/scale),["x"]=(XBar["RF_X"]/scale),["point"]="TOPLEFT",["relativePoint"]="TOPLEFT",["relativeTo"]="UIParent",}
                        else ChatFrame1:AddMessage("XBar-Error: no globals to inject.",1,0,0); end
                        RaidPartyFrame1:ClearAllAnchors();
                        RaidPartyFrame1:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["RF_X"]/scale,XBar["RF_Y"]/scale);
                end
                if (XBar["HF"]==true) then
                        if (XBar["HF_Anchor"]==true) then XFrameHF:Show(); else XFrameHF:Hide(); end
                        HouseFrame:ClearAllAnchors();
                        HouseFrame:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["HF_X"]/scale,XBar["HF_Y"]/scale);
                end
                if (XBar["CF"]==true) then
                        if (XBar["CF_Anchor"]==true) then XFrameCF:Show(); else XFrameCF:Hide(); end
                        ChatFrame1:ClearAllAnchors();
                        ChatFrame1:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["CF_X"]/scale,XBar["CF_Y"]/scale);
                end
                if (XBar["MF_Anchor"]==true) then XFrameMF:Show(); else XFrameMF:Hide(); end
                if (XBar["MF_Double"]==true) then XFrameMF:SetScale(2); XFrameMF_Shadow:SetScale(2); else XFrameMF:SetScale(1); XFrameMF_Shadow:SetScale(1); end
                if (XBar["MF_Title"]==true) then
                        if (XBar["MF_Style"]>1) then XFrameMF_Title:Show(); MinimapFrameBorder:Hide();
                        else XFrameMF_Title:Hide(); MinimapFrameBorder:Show(); end
                else XFrameMF_Title:Hide(); MinimapFrameBorder:Hide(); end
                XBar_MMUpdate(XBar["MF_Buttons"]);
                if (XBar["MF"]==true) then
                        XFrameMF_Title:ClearAllAnchors();
                        XFrameMF_Title:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["MF_Title_X"]/scale,XBar["MF_Title_Y"]/scale);
                        if (XBar["MF_Time"]==true) then
                                if (XBar["MF_Time_Anchor"]==true) then XFrameMFTimeShadow:Show(); else XFrameMFTimeShadow:Hide(); end
                                MinimapFrameTime:ClearAllAnchors();
                                MinimapFrameTime:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["MF_Time_X"]/scale,XBar["MF_Time_Y"]/scale);
                                MinimapFrameTime:Show();
                        else MinimapFrameTime:Hide(); end
                        if (XBar["MF_Style"]>1) then
                                MINIMAPFRAME_MASK_NAME="Interface\\AddOns\\XBar\\Img\\Map\\Map_Mask_"..mdsgn[XBar["MF_Style"]]..".tga";
                                MINIMAPFRAME_RIMFRAME1="Interface\\AddOns\\XBar\\Img\\Map\\Map_Bgnd_"..mdsgn[XBar["MF_Style"]].."1.tga";
                                MINIMAPFRAME_RIMFRAME2="Interface\\AddOns\\XBar\\Img\\Map\\Map_Bgnd_"..mdsgn[XBar["MF_Style"]].."2.tga";
                                MinimapFrame:SetSize((XBar["MF_Size"] or 128),(XBar["MF_Size"] or 128));
                                MinimapFrame:ClearAllAnchors();
                                MinimapFrame:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["MF_X"]/scale,XBar["MF_Y"]/scale);
                                MinimapRimFrame:SetSize((XBar["MF_Size"] or 128),(XBar["MF_Size"] or 128));
                                MinimapRimFrame:ClearAllAnchors();
                                MinimapRimFrame:SetAnchor("CENTER","CENTER",MinimapFrame,0,0);
                                MinimapRimFrameTexture1:SetSize((XBar["MF_Size"] or 128),(XBar["MF_Size"]/2 or 56));
                                MinimapRimFrameTexture1:SetTexture(MINIMAPFRAME_RIMFRAME1);
                                MinimapRimFrameTexture2:SetSize((XBar["MF_Size"] or 128),(XBar["MF_Size"]/2 or 56));
                                MinimapRimFrameTexture2:SetTexture(MINIMAPFRAME_RIMFRAME2);
                                MinimapViewFrame:SetSize((XBar["MF_Size"] or 128),(XBar["MF_Size"] or 128));
                                MinimapViewFrame:ClearAllAnchors();
                                MinimapViewFrame:SetAnchor("CENTER","CENTER",MinimapFrame,0,0);
                                MinimapFramePlusButton:SetScale(.7);
                                MinimapFramePlusButton:ClearAllAnchors();
                                MinimapFramePlusButton:SetAnchor("TOP","BOTTOM",MinimapViewFrame,57,0);
                                MinimapFrameMinusButton:SetScale(.7);
                                MinimapFrameMinusButton:ClearAllAnchors();
                                MinimapFrameMinusButton:SetAnchor("TOP","BOTTOM",MinimapViewFrame,-57,0);
                                MinimapFramePlayerPosition:SetScale(1);
                                MinimapFramePlayerPosition:ClearAllAnchors();
                                MinimapFramePlayerPosition:SetAnchor("TOP","BOTTOM",MinimapViewFrame,0,0);
                                MinimapDisableFrame:Hide();
                                MinimapFrameBorder:Hide();
                        else
                                MINIMAPFRAME_MASK_NAME="Interface\\Minimap\\MinimapBorder_Mask";
                                MINIMAPFRAME_RIMFRAME1="Interface\\Minimap\\MinimapBorder_Middle.tga";
                                MINIMAPFRAME_RIMFRAME2="Interface\\Minimap\\MinimapBorder_Buttom.tga";
                                MinimapFrame:SetSize(150,150);
                                MinimapFrame:ClearAllAnchors();
                                MinimapFrame:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["MF_X"]/scale,XBar["MF_Y"]/scale);
                                MinimapFrameBorder:ClearAllAnchors();
                                MinimapFrameBorder:SetAnchor("BOTTOMRIGHT","TOPRIGHT","MinimapFrame",12,269);
                                MinimapRimFrame:SetSize(256,256);
                                MinimapRimFrame:ClearAllAnchors();
                                MinimapRimFrame:SetAnchor("TOPRIGHT","TOPRIGHT",MinimapFrame,5,0);
                                MinimapRimFrameTexture1:SetSize(256,64);
                                MinimapRimFrameTexture1:SetTexture(MINIMAPFRAME_RIMFRAME1);
                                MinimapRimFrameTexture2:SetSize(256,128);
                                MinimapRimFrameTexture2:SetTexture(MINIMAPFRAME_RIMFRAME2);
                                MinimapViewFrame:SetSize(150,150);
                                MinimapViewFrame:ClearAllAnchors();
                                MinimapViewFrame:SetAnchor("TOP","TOP",MinimapFrame,0,0);
                                MinimapFramePlusButton:SetScale(1);
                                MinimapFramePlusButton:ClearAllAnchors();
                                MinimapFramePlusButton:SetAnchor("CENTER","CENTER",MinimapViewFrame,64.301,47.595);
                                MinimapFrameMinusButton:SetScale(1);
                                MinimapFrameMinusButton:ClearAllAnchors();
                                MinimapFrameMinusButton:SetAnchor("CENTER","CENTER",MinimapViewFrame,44.328,66.595);
                                MinimapFramePlayerPosition:SetScale(1);
                                MinimapFramePlayerPosition:ClearAllAnchors();
                                MinimapFramePlayerPosition:SetAnchor("CENTER","BOTTOM",MinimapViewFrame,0,0);
                                MinimapDisableFrame:Hide();
                                MinimapFrameTime:Show();
                        end
                        InitializeMiniMap("MinimapViewFrame",MINIMAPFRAME_MASK_NAME,"MinimapFramePlayerCursor","MinimapFrameDuelRange","MinimapFrame_Icon",30);
                end
                XBarAfk:ClearAllAnchors();
                XBarAfk:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["AfkMsg_X"]/scale,XBar["AfkMsg_Y"]/scale);
                XBarAfk_Logo:ClearAllAnchors();
                XBarAfk_Logo:SetAnchor("TOPLEFT","TOPLEFT","UIParent",XBar["AfkLogo_X"]/scale,XBar["AfkLogo_Y"]/scale);
        end
        if not (xload==true) then DEFAULT_CHAT_FRAME:AddMessage(XLng["Chat"]["loaded1"]..version..XLng["Chat"]["loaded2"],1,1,1); end
end

function XBar_Toggle()
        if (XBarFrame:IsVisible()) then
                        XBarFrame:Hide();
                        adBottomArtFrame:Hide(); else
                                XBarFrame:Show();
                                adBottomArtFrame:Show();
                end
end

function XBar_ToggleUIPanel(this)
        PlaySoundByPath("sound\\interface\\ui_generic_click.mp3");
        if (this:IsVisible()) then this:Hide(); else this:Show(); end
end

function XBar_ToggleBgnd(this)
        PlaySoundByPath("sound\\interface\\ui_generic_click.mp3");
        if (XBar["Style"]<#xdsgn) then XBar["Style"]=XBar["Style"]+1; else XBar["Style"]=1; end
        XBar_OnEvent(this,"VARIABLES_LOADED",true);
end

function XBar_ToggleSound(this)
        PlaySoundByPath("sound\\interface\\ui_generic_click.mp3");
        local vol=SYS_AudioSettings_MasterVolumeSlider:GetValue();
        if (XBar["Muted"]) then
                SYS_AudioSettings_MasterVolumeSlider:SetValue(XBar["Muted"]);
                getglobal("XBarSndBtn_nTexture"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\SndBtn_Normal.tga");
                XBar["Muted"]=nil;
        else
                XBar["Muted"]=vol;
                SYS_AudioSettings_MasterVolumeSlider:SetValue(0);
                getglobal("XBarSndBtn_nTexture"):SetTexture("Interface\\Addons\\XBar\\Img\\Bar\\"..xdsgn[XBar["Style"]].."\\SndBtn_Muted.tga");
        end
        SSF_AudioSettings_OnApply();
        HideUIPanel(SYS_Settings_Frame);
end

function XBar_SpecialMenu(key,this)
        PlaySoundByPath("sound\\interface\\ui_generic_click.mp3");
        if (key=="LBUTTON") then
                XBar_PopupMenu.Buttons=XBarMainButtons;
                XBar_PopupMenu_Toggle("UIParent",0,32,false);
        elseif (key=="RBUTTON") then
                XBar_PopupMenu.Buttons=XBarSystemButtons;
                XBar_PopupMenu_Toggle("UIParent",0,32,false); end
end

function XBar_BonusMenu(key,this)
        PlaySoundByPath("sound\\interface\\ui_generic_click.mp3");
        if (key=="LBUTTON") then
                XBar_PopupMenu.Buttons=XBarBonusButtons;
                XBar_PopupMenu_Toggle("UIParent",0,32,false); end
end

function XBar_MoveStart(key,this)
        if (key=="RBUTTON") then this:StartMoving(); end
end

function XBar_MoveEnd(this)
        this:StopMovingOrSizing();
        XBar["AfkLogo_X"],XBar["AfkLogo_Y"]        =XBarAfk_Logo:GetPos();
        XBar["AfkMsg_X"],XBar["AfkMsg_Y"]        =XBarAfk:GetPos();
        XBar["Ammo_X"],Y                                                        =XBarAmmo:GetPos();
        XBar["Bag_X"],Y                                                        =XBarBag:GetPos();
        XBar["Clock_X"],Y                                                        =XBarClock:GetPos();
        XBar["Dps_X"],Y                                                        =XBarDps:GetPos();
        XBar["Exp_X"],Y                                                        =XBarExp:GetPos();
        XBar["Friend_X"],Y                                                =XBarFriend:GetPos();
        XBar["Guild_X"],Y                                                        =XBarGuild:GetPos();
        XBar["Klass_X"],Y                                                        =XBarKlass:GetPos();
        XBar["Mail_X"],Y                                                        =XBarMail:GetPos();
        XBar["Money_X"],Y                                                        =XBarMoney:GetPos();
        XBar["Ping_X"],Y                                                        =XBarPing:GetPos();
        XBar_OnEvent(this,"VARIABLES_LOADED",true);
end

function XBar_MMToggle(key,this,hide)
        if (key=="RBUTTON") then
                if not (IsShiftKeyDown()) then
                        if (WorldMapFrame:IsVisible()) then WorldMapFrame:Hide(); else WorldMapFrame:Show(); end
                end
        elseif (key=="LBUTTON") then
                if (hide==true) then
                        XFrameMF:Hide();
                        XFrameMF_Shadow:Show();
                        MinimapFrame:Hide();
                        MinimapViewFrame:Hide();
                        MinimapFramePlusButton:Hide();
                        MinimapFrameMinusButton:Hide();
                        MinimapFramePlayerPosition:Hide()
                        XBar_MMUpdate(true);
                else
                        XFrameMF:Show();
                        XFrameMF_Shadow:Hide();
                        MinimapFrame:Show();
                        MinimapViewFrame:Show();
                        MinimapFramePlusButton:Show();
                        MinimapFrameMinusButton:Show();
                        MinimapFramePlayerPosition:Show()
                        XBar_MMUpdate(false);
                end
        end
end

function XBar_MMUpdate(show)
        if (show==false or XFrameMF_Shadow:IsVisible()) then
                MinimapBeautyStudioButton:Hide();
                MinimapFrameBulletinButton:Hide();
                MinimapFrameOptionButton:Hide();
                MinimapFrameQuestTrackButton:Hide();
                MinimapFrameRestoreUIButton:Hide();
                MinimapFrameStoreButton:Hide();
                MinimapNpcTrackButton:Hide();
    MinimapFrameBattleGroundButton:Hide();
    MinimapFramePlusButton:Hide();
    MinimapFrameMinusButton:Hide();
        elseif (show==true) then
                if (XFrameMF:IsVisible()) then
                        MinimapBeautyStudioButton:Show();
                        MinimapFrameBulletinButton:Show();
                        MinimapFrameOptionButton:Show();
                        MinimapFrameQuestTrackButton:Show();
                        MinimapFrameRestoreUIButton:Show();
                        MinimapFrameStoreButton:Show();
                        MinimapNpcTrackButton:Show();
      MinimapFrameBattleGroundButton:Show();
      MinimapFramePlusButton:Show();
      MinimapFrameMinusButton:Show();
                end
        end
        return;
end

function XBar_SetDecimals(value)
        local reverse=string.reverse(value);
        local laenge=string.len(reverse);
        local ergebnis=value;
        if (laenge<4) then ergebnis=string.sub(reverse,1);
        elseif (laenge<7) then ergebnis=string.sub(reverse,1,3).."."..string.sub(reverse,4);
        elseif (laenge<10) then ergebnis=string.sub(reverse,1,3).."."..string.sub(reverse,4,6).."."..string.sub(reverse,7);
        else ergebnis=string.sub(reverse,1,3).."."..string.sub(reverse,4,6).."."..string.sub(reverse,7,9).."."..string.sub(reverse,8); end
        value=string.reverse(ergebnis);
        return value;
end

function XBar_Round(num,idp)
        local mult=10^(idp or 0);
        return math.floor(num*mult+.5)/mult;
end

function XBar_StrReplace(a,b,c)
        return string.gsub(a,b,c);
end

function XBar_LoadFile(filename)
        local array,err=loadfile(filename);
        if err then        return false, err; end
        return dofile(filename);
end
-- #################################################################################################################
-- XFrames
-- #################################################################################################################
function XFrame_MoveStart(key,this,dummy)
        if (dummy) then this:StartMoving("TOPLEFT");
        elseif (key=="RBUTTON" and IsShiftKeyDown()) then this:GetParent():StartMoving("TOPLEFT"); end
end

function XFrame_MoveEnd(this,dummy,frame)
        this:StopMovingOrSizing(); this:GetParent():StopMovingOrSizing();
        if (dummy) then
                local scale=GetUIScale();
                local posX,posY;
                posX,posY=this:GetPos();
                getglobal(frame):ClearAllAnchors();
                getglobal(frame):SetAnchor("TOPLEFT","TOPLEFT","UIParent",posX/scale,posY/scale);
                this:Hide();
        end
        XBar["PF_X"],XBar["PF_Y"]=PlayerFrame:GetPos();
        XBar["TF_X"],XBar["TF_Y"]=TargetFrame:GetPos();
        XBar["TT_X"],XBar["TT_Y"]=TargetTargetFrame:GetPos();
        XBar["TT_X"]=XBar["TT_X"]/TargetTargetFrame:GetScale();
        XBar["TT_Y"]=XBar["TT_Y"]/TargetTargetFrame:GetScale();
        XBar["BF_X"],XBar["BF_Y"]=PlayerBuffButton1:GetPos();
        XBar["DB_X"],XBar["DB_Y"]=PlayerDebuffButton1:GetPos();
        XBar["CB_X"],XBar["CB_Y"]=CastingBarFrame:GetPos();
        XBar["XP_Xs"],XBar["XP_Ys"]=ExperienceFrame:GetPos();
        XBar["PT_X"],XBar["PT_Y"]=UnitFrame_party1:GetPos();
        XBar["RF_X"],XBar["RF_Y"]=RaidPartyFrame1:GetPos();
        XBar["MF_X"],XBar["MF_Y"]=MinimapFrame:GetPos();
        XBar["MF_Title_X"],XBar["MF_Title_Y"]=XFrameMF_Title:GetPos();
        XBar["MF_Time_X"],XBar["MF_Time_Y"]=MinimapFrameTime:GetPos();
        XBar["HF_X"],XBar["HF_Y"]=HouseFrame:GetPos();
        XBar["CF_X"],XBar["CF_Y"]=ChatFrame1:GetPos();

        XBarCfg_OnShow(getglobal("XBarCfg"));
end

function XFrame_ShowDummy(this,frame,target)
        if (frame) then
                if (getglobal(frame):IsVisible()) then getglobal(frame):Hide();
                else
                        getglobal(frame):SetWidth(getglobal(target):GetWidth());
                        getglobal(frame):SetHeight(getglobal(target):GetHeight());
                        getglobal(frame):Show();
                end
        end
end

-- #################################################################################################################
-- XBar Configuration
-- #################################################################################################################
function XBarCfg_OnShow(this)
        if (XBar["Position"]=="TOP") then XBarCfg_G_CB_XE_T:SetChecked(true); XBarCfg_G_CB_XE_B:SetChecked(false);
        else XBarCfg_G_CB_XE_B:SetChecked(true); XBarCfg_G_CB_XE_T:SetChecked(false); end
        XBarCfg_G_CB_XE:SetChecked                        ((XBar["Enable"] and 1) or nil);
        XBarCfg_G_CB_MB:SetChecked                        ((XBar["Menu"] and 1) or nil);
        UIDropDownMenu_SetSelectedID                (XBarCfg_G_Style,XBar["Style"]); XBarCfg_G_StyleText:SetText(xdsgn[XBar["Style"]]);
        XBarCfg_G_CB_MF:SetChecked                        ((XBar["MainMenuFrame"] and 1) or nil);
        XBarCfg_G_CB_EF:SetChecked                        ((XBar["ExperienceFrame"] and 1) or nil);
        XBarCfg_G_CB_DF:SetChecked                        ((XBar["EquipDameFrame"] and 1) or nil);
        XBarCfg_G_SR_Alpha:SetValue                (tonumber(XBar["Alpha"]));
        XBarCfg_Spam_Enable:SetChecked        ((XBar["Spam"] and 1) or nil);
        XBarCfg_Afk_Enable:SetChecked                ((XBar["AfkEnable"] and 1) or nil);
        XBarCfg_Afk_KeepMsg:SetChecked        ((XBar["AfkKeepMsg"] and 1) or nil);
        XBarCfg_Afk_AutoAfk:SetChecked        ((XBar["AfkAuto"] and 1) or nil);
        XBarCfg_Afk_Timer:SetText                        (tonumber(XBar["AfkTimer"]));
        XBarCfg_Afk_KeepAfk:SetChecked        ((XBar["AfkMind"] and 1) or nil);
        XBarCfg_Afk_Value1:SetText                        ((XBar["AfkV1"]) or "<AFK> im currently away from keyboard.");
        XBarCfg_Afk_Value2:SetText                        ((XBar["AfkV2"]) or "<DND> please do not disturb.");
        XBarCfg_B_Ammo_Show:SetChecked        ((XBar["Ammo"] and 1) or nil);
        XBarCfg_B_Ammo_Text1:SetChecked        ((XBar["AmmoT1"] and 1) or nil);
        XBarCfg_B_Ammo_Value1:SetText                ((XBar["AmmoV1"]) or "[AMMO]");
        XBarCfg_B_Ammo_Text2:SetChecked        ((XBar["AmmoT2"] and 1) or nil);
        XBarCfg_B_Ammo_Value2:SetText                ((XBar["AmmoV2"]) or "");
        XBarCfg_B_Bag_Show:SetChecked                ((XBar["Bag"] and 1) or nil);
        XBarCfg_B_Bag_Text1:SetChecked        ((XBar["BagT1"] and 1) or nil);
        XBarCfg_B_Bag_Value1:SetText                ((XBar["BagV1"]) or "Slots: [USED] / [TOTAL]");
        XBarCfg_B_Bag_Text2:SetChecked        ((XBar["BagT2"] and 1) or nil);
        XBarCfg_B_Bag_Value2:SetText                ((XBar["BagV2"]) or "Used: [LOAD] %");
        XBarCfg_B_Clock_Show:SetChecked        ((XBar["Clock"] and 1) or nil);
        XBarCfg_B_Clock_Text1:SetChecked        ((XBar["ClockT1"] and 1) or nil);
        XBarCfg_B_Clock_Value1:SetText        ((XBar["ClockV1"]) or "Time: [TIME24]");
        XBarCfg_B_Clock_Value2:SetText        ((XBar["ClockV2"]) or "Time: [TIME12]");
        XBarCfg_B_Clock_Value3:SetText        ((XBar["ClockV3"]) or "Date: [DATE]");
        XBarCfg_B_Clock_Text2:SetChecked        ((XBar["ClockT2"] and 1) or nil);
        XBarCfg_B_Clock_Value4:SetText        ((XBar["ClockV4"]) or "Game: [ONLINE]");
        XBarCfg_B_Clock_Value5:SetText        ((XBar["ClockV5"]) or "Total: [TOTALONLINE]");
        XBarCfg_B_Dps_Show:SetChecked                ((XBar["Dps"] and 1) or nil);
        XBarCfg_B_Dps_Text1:SetChecked        ((XBar["DpsT1"] and 1) or nil);
        XBarCfg_B_Dps_Value1:SetText                ((XBar["DpsV1"]) or "DPS: [DPS]");
        XBarCfg_B_Dps_Text2:SetChecked        ((XBar["DpsT2"] and 1) or nil);
        XBarCfg_B_Dps_Value2:SetText                ((XBar["DpsV2"]) or "kills: [KILLS]");
        XBarCfg_B_Exp_Show:SetChecked                ((XBar["Exp"] and 1) or nil);
        XBarCfg_B_Exp_Text1:SetChecked        ((XBar["ExpT1"] and 1) or nil);
        XBarCfg_B_Exp_Value1:SetText                ((XBar["ExpV1"]) or "TP: [TP]");
        XBarCfg_B_Exp_Text2:SetChecked        ((XBar["ExpT2"] and 1) or nil);
        XBarCfg_B_Exp_Value2:SetText                ((XBar["ExpV2"]) or "XP: [EXPNOW] / [EXPFULL] [EXPPERCENT]");
        XBarCfg_B_Friend_Show:SetChecked        ((XBar["Friend"] and 1) or nil);
        XBarCfg_B_Friend_Text1:SetChecked((XBar["FriendT1"] and 1) or nil);
        XBarCfg_B_Friend_Value1:SetText        ((XBar["FriendV1"]) or "");
        XBarCfg_B_Friend_Text2:SetChecked((XBar["FriendT2"] and 1) or nil);
        XBarCfg_B_Friend_Value2:SetText        ((XBar["FriendV2"]) or "[ONLINE]");
        XBarCfg_B_Guild_Show:SetChecked        ((XBar["Guild"] and 1) or nil);
        XBarCfg_B_Guild_Text1:SetChecked        ((XBar["GuildT1"] and 1) or nil);
        XBarCfg_B_Guild_Value1:SetText        ((XBar["GuildV1"]) or "[GNAME]");
        XBarCfg_B_Guild_Text2:SetChecked        ((XBar["GuildT2"] and 1) or nil);
        XBarCfg_B_Guild_Value2:SetText        ((XBar["GuildV2"]) or "[ONLINE]");
        XBarCfg_B_Klass_Show:SetChecked        ((XBar["Klass"] and 1) or nil);
        XBarCfg_B_Klass_Text1:SetChecked        ((XBar["KlassT1"] and 1) or nil);
        XBarCfg_B_Klass_Value1:SetText        ((XBar["KlassV1"]) or "[MCLASS]: [MLVL]");
        XBarCfg_B_Klass_Text2:SetChecked        ((XBar["KlassT2"] and 1) or nil);
        XBarCfg_B_Klass_Value2:SetText        ((XBar["KlassV2"]) or "[SCLASS]: [SLVL]");
        XBarCfg_B_Mail_Show:SetChecked        ((XBar["Mail"] and 1) or nil);
        XBarCfg_B_Mail_Text1:SetChecked        ((XBar["MailT1"] and 1) or nil);
        XBarCfg_B_Mail_Value1:SetText                ((XBar["MailV1"]) or "New: [UNREAD]");
        XBarCfg_B_Mail_Text2:SetChecked        ((XBar["MailT2"] and 1) or nil);
        XBarCfg_B_Mail_Value2:SetText                ((XBar["MailV2"]) or "");
        XBarCfg_B_Money_Show:SetChecked        ((XBar["Money"] and 1) or nil);
        XBarCfg_B_Money_Text1:SetChecked        ((XBar["MoneyT1"] and 1) or nil);
        XBarCfg_B_Money_Value1:SetText        ((XBar["MoneyV1"]) or "Gold: [GOLD]");
        XBarCfg_B_Money_Text2:SetChecked        ((XBar["MoneyT2"] and 1) or nil);
        XBarCfg_B_Money_Value2:SetText        ((XBar["MoneyV2"]) or "Dias: [DIAS]");
        XBarCfg_B_Ping_Show:SetChecked        ((XBar["Ping"] and 1) or nil);
        XBarCfg_B_Ping_Text1:SetChecked        ((XBar["PingT1"] and 1) or nil);
        XBarCfg_B_Ping_Value1:SetText                ((XBar["PingV1"]) or "ms: [MS]");
        XBarCfg_B_Ping_Text2:SetChecked        ((XBar["PingT2"] and 1) or nil);
        XBarCfg_B_Ping_Value2:SetText                ((XBar["PingV2"]) or "Fps: [FPS]");
        XBarCfg_X_PF_CB:SetChecked                        ((XBar["PF"] and 1) or nil);
        XBarCfg_X_PF_XA:SetChecked                        ((XBar["PF_Anchor"] and 1) or nil);
        XBarCfg_X_PF_X:SetText                                (math.floor(XBar["PF_X"]));
        XBarCfg_X_PF_Y:SetText                                (math.floor(XBar["PF_Y"]));
        XBarCfg_X_TF_CB:SetChecked                        ((XBar["TF"] and 1) or nil);
        XBarCfg_X_TF_XA:SetChecked                        ((XBar["TF_Anchor"] and 1) or nil);
        XBarCfg_X_TF_X:SetText                                (math.floor(XBar["TF_X"]));
        XBarCfg_X_TF_Y:SetText                                (math.floor(XBar["TF_Y"]));
        XBarCfg_X_TT_CB:SetChecked                        ((XBar["TT"] and 1) or nil);
        XBarCfg_X_TT_XA:SetChecked                        ((XBar["TT_Anchor"] and 1) or nil);
        XBarCfg_X_TT_X:SetText                                (math.floor(XBar["TT_X"]));
        XBarCfg_X_TT_Y:SetText                                (math.floor(XBar["TT_Y"]));
        XBarCfg_X_BF_CB:SetChecked                        ((XBar["BF"] and 1) or nil);
        XBarCfg_X_BF_XA:SetChecked                        ((XBar["BF_Anchor"] and 1) or nil);
        XBarCfg_X_BF_X:SetText                                (math.floor(XBar["BF_X"]));
        XBarCfg_X_BF_Y:SetText                                (math.floor(XBar["BF_Y"]));
        XBarCfg_X_DB_CB:SetChecked                        ((XBar["DB"] and 1) or nil);
        XBarCfg_X_DB_XA:SetChecked                        ((XBar["DB_Anchor"] and 1) or nil);
        XBarCfg_X_DB_X:SetText                                (math.floor(XBar["DB_X"]));
        XBarCfg_X_DB_Y:SetText                                (math.floor(XBar["DB_Y"]));
        XBarCfg_X_CB_CB:SetChecked                        ((XBar["CB"] and 1) or nil);
        XBarCfg_X_CB_XA:SetChecked                        ((XBar["CB_Anchor"] and 1) or nil);
        XBarCfg_X_CB_X:SetText                                (math.floor(XBar["CB_X"]));
        XBarCfg_X_CB_Y:SetText                                (math.floor(XBar["CB_Y"]));
        XBarCfg_X_XP_CB:SetChecked                        ((XBar["XP"] and 1) or nil);
        XBarCfg_X_XP_XA:SetChecked                        ((XBar["XP_Anchor"] and 1) or nil);
        XBarCfg_X_XP_Xs:SetText                                (math.floor(XBar["XP_Xs"]));
        XBarCfg_X_XP_Ys:SetText                                (math.floor(XBar["XP_Ys"]));
        XBarCfg_X_XP_Xe:SetText                                (math.floor(XBar["XP_Xe"]));
        XBarCfg_X_XP_Ye:SetText                                (math.floor(XBar["XP_Ye"]));
        XBarCfg_X_XP_H:SetText                                (math.floor(XBar["XP_H"]));
        XBarCfg_X_PT_CB:SetChecked                        ((XBar["PT"] and 1) or nil);
        XBarCfg_X_PT_XA:SetChecked                        ((XBar["PT_Anchor"] and 1) or nil);
        XBarCfg_X_PT_X:SetText                                (math.floor(XBar["PT_X"]));
        XBarCfg_X_PT_Y:SetText                                (math.floor(XBar["PT_Y"]));
        XBarCfg_X_RF_CB:SetChecked                        ((XBar["RF"] and 1) or nil);
        XBarCfg_X_RF_XA:SetChecked                        ((XBar["RF_Anchor"] and 1) or nil);
        XBarCfg_X_RF_X:SetText                                (math.floor(XBar["RF_X"]));
        XBarCfg_X_RF_Y:SetText                                (math.floor(XBar["RF_Y"]));
        XBarCfg_X_MF_CB:SetChecked                        ((XBar["MF"] and 1) or nil);
        XBarCfg_X_MF_XA:SetChecked                        ((XBar["MF_Anchor"] and 1) or nil);
        XBarCfg_X_MF_X:SetText                                (math.floor(XBar["MF_X"]));
        XBarCfg_X_MF_Y:SetText                                (math.floor(XBar["MF_Y"]));
        XBarCfg_X_MF_Time_CB:SetChecked        ((XBar["MF_Time"] and 1) or nil);
        XBarCfg_X_MF_Time_XA:SetChecked        ((XBar["MF_Time_Anchor"] and 1) or nil);
        XBarCfg_X_MF_Time_X:SetText                (math.floor(XBar["MF_Time_X"]));
        XBarCfg_X_MF_Time_Y:SetText                (math.floor(XBar["MF_Time_Y"]));
        XBarCfg_X_MF_Title_CB:SetChecked                ((XBar["MF_Title"] and 1) or nil);
        XBarCfg_X_MF_Title_XA:SetChecked        ((XBar["MF_Title_Anchor"] and 1) or nil);
        XBarCfg_X_MF_Title_X:SetText                (math.floor(XBar["MF_Title_X"]));
        XBarCfg_X_MF_Title_Y:SetText                (math.floor(XBar["MF_Title_Y"]));
        XBarCfg_X_MF_DblXFrame:SetChecked((XBar["MF_Double"] and 1) or nil);
        UIDropDownMenu_SetSelectedID                (XBarCfg_X_MF_Style,XBar["MF_Style"]);
        XBarCfg_X_MF_StyleText:SetText        (mdsgn[XBar["MF_Style"]]);
        XBarCfg_X_MF_Size:SetText                        (math.floor(XBar["MF_Size"]));
        XBarCfg_X_MF_Buttons:SetChecked        ((XBar["MF_Buttons"] and 1) or nil);
        XBarCfg_X_HF_CB:SetChecked                        ((XBar["HF"] and 1) or nil);
        XBarCfg_X_HF_XA:SetChecked                        ((XBar["HF_Anchor"] and 1) or nil);
        XBarCfg_X_HF_X:SetText                                (math.floor(XBar["HF_X"]));
        XBarCfg_X_HF_Y:SetText                                (math.floor(XBar["HF_Y"]));
        XBarCfg_X_CF_CB:SetChecked                        ((XBar["CF"] and 1) or nil);
        XBarCfg_X_CF_XA:SetChecked                        ((XBar["CF_Anchor"] and 1) or nil);
        XBarCfg_X_CF_X:SetText                                (math.floor(XBar["CF_X"]));
        XBarCfg_X_CF_Y:SetText                                (math.floor(XBar["CF_Y"]));
end

function XBarCfg_Save()
        if (XBarCfg_G_CB_XE_T:IsChecked()) then XBar["Position"]="TOP" else XBar["Position"]="BOTTOM"; end
        XBar["Enable"]=                        (XBarCfg_G_CB_XE:IsChecked() and true) or false;
        XBar["Menu"]=                                (XBarCfg_G_CB_MB:IsChecked() and true) or false;
        XBar["Style"]=                                (UIDropDownMenu_GetSelectedID(XBarCfg_G_Style));
        XBar["MainMenuFrame"]=        (XBarCfg_G_CB_MF:IsChecked() and true) or false;
        XBar["ExperienceFrame"]=(XBarCfg_G_CB_EF:IsChecked() and true) or false;
        XBar["EquipDameFrame"]=        (XBarCfg_G_CB_DF:IsChecked() and true) or false;
        XBar["Alpha"]=                                (XBarCfg_G_SR_Alpha:GetValue());
        XBar["Spam"]=                                (XBarCfg_Spam_Enable:IsChecked() and true) or false;
        XBar["AfkEnable"]=                (XBarCfg_Afk_Enable:IsChecked() and true) or false;
        XBar["AfkKeepMsg"]=                (XBarCfg_Afk_KeepMsg:IsChecked() and true) or false;
        XBar["AfkAuto"]=                        (XBarCfg_Afk_AutoAfk:IsChecked() and true) or false;
        XBar["AfkTimer"]=                        (tonumber(XBarCfg_Afk_Timer:GetText()) or 600);
        XBar["AfkMind"]=                        (XBarCfg_Afk_KeepAfk:IsChecked() and true) or false;
        XBar["AfkV1"]=                                (XBarCfg_Afk_Value1:GetText()) or XLng["XAddon"]["AfkMsg"];
        XBar["AfkV2"]=                                (XBarCfg_Afk_Value2:GetText()) or XLng["XAddon"]["DndMsg"];
        XBar["Ammo"]=                                (XBarCfg_B_Ammo_Show:IsChecked() and true) or false;
        XBar["AmmoT1"]=                        (XBarCfg_B_Ammo_Text1:IsChecked() and true) or false;
        XBar["AmmoV1"]=                        (XBarCfg_B_Ammo_Value1:GetText()) or "[AMMO]";
        XBar["AmmoT2"]=                        (XBarCfg_B_Ammo_Text2:IsChecked() and true) or false;
        XBar["AmmoV2"]=                        (XBarCfg_B_Ammo_Value2:GetText()) or "";
        XBar["Bag"]=                                (XBarCfg_B_Bag_Show:IsChecked() and true) or false;
        XBar["BagT1"]=                                (XBarCfg_B_Bag_Text1:IsChecked() and true) or false;
        XBar["BagV1"]=                                (XBarCfg_B_Bag_Value1:GetText()) or "Slots: [USED] / [TOTAL]";
        XBar["BagT2"]=                                (XBarCfg_B_Bag_Text2:IsChecked() and true) or false;
        XBar["BagV2"]=                                (XBarCfg_B_Bag_Value2:GetText()) or "Used: [LOAD] %";
        XBar["Clock"]=                                (XBarCfg_B_Clock_Show:IsChecked() and true) or false;
        XBar["ClockT1"]=                        (XBarCfg_B_Clock_Text1:IsChecked() and true) or false;
        XBar["ClockV1"]=                        (XBarCfg_B_Clock_Value1:GetText()) or "Time: [TIME24]";
        XBar["ClockV2"]=                        (XBarCfg_B_Clock_Value2:GetText()) or "Time: [TIME12]";
        XBar["ClockV3"]=                        (XBarCfg_B_Clock_Value3:GetText()) or "Date: [DATE]";
        XBar["ClockT2"]=                        (XBarCfg_B_Clock_Text2:IsChecked() and true) or false;
        XBar["ClockV4"]=                        (XBarCfg_B_Clock_Value4:GetText()) or "Total: [TOTALONLINE]";
        XBar["ClockV5"]=                        (XBarCfg_B_Clock_Value5:GetText()) or "Game: [ONLINE]";
        XBar["Dps"]=                                (XBarCfg_B_Dps_Show:IsChecked() and true) or false;
        XBar["DpsT1"]=                                (XBarCfg_B_Dps_Text1:IsChecked() and true) or false;
        XBar["DpsV1"]=                                (XBarCfg_B_Dps_Value1:GetText()) or "DPS: [DPS]";
        XBar["DpsT2"]=                                (XBarCfg_B_Dps_Text2:IsChecked() and true) or false;
        XBar["DpsV2"]=                                (XBarCfg_B_Dps_Value2:GetText()) or "kills: [KILLS]";
        XBar["Exp"]=                                (XBarCfg_B_Exp_Show:IsChecked() and true) or false;
        XBar["ExpT1"]=                                (XBarCfg_B_Exp_Text1:IsChecked() and true) or false;
        XBar["ExpV1"]=                                (XBarCfg_B_Exp_Value1:GetText()) or "TP: [TP]";
        XBar["ExpT2"]=                                (XBarCfg_B_Exp_Text2:IsChecked() and true) or false;
        XBar["ExpV2"]=                                (XBarCfg_B_Exp_Value2:GetText()) or "XP: [EXPNOW] / [EXPFULL] [EXPPERCENT]";
        XBar["Friend"]=                        (XBarCfg_B_Friend_Show:IsChecked() and true) or false;
        XBar["FriendT1"]=                        (XBarCfg_B_Friend_Text1:IsChecked() and true) or false;
        XBar["FriendV1"]=                        (XBarCfg_B_Friend_Value1:GetText()) or "";
        XBar["FriendT2"]=                        (XBarCfg_B_Friend_Text2:IsChecked() and true) or false;
        XBar["FriendV2"]=                        (XBarCfg_B_Friend_Value2:GetText()) or "[ONLINE]";
        XBar["Guild"]=                                (XBarCfg_B_Guild_Show:IsChecked() and true) or false;
        XBar["GuildT1"]=                        (XBarCfg_B_Guild_Text1:IsChecked() and true) or false;
        XBar["GuildV1"]=                        (XBarCfg_B_Guild_Value1:GetText()) or "[GNAME]";
        XBar["GuildT2"]=                        (XBarCfg_B_Guild_Text2:IsChecked() and true) or false;
        XBar["GuildV2"]=                        (XBarCfg_B_Guild_Value2:GetText()) or "[ONLINE]";
        XBar["Klass"]=                                (XBarCfg_B_Klass_Show:IsChecked() and true) or false;
        XBar["KlassT1"]=                        (XBarCfg_B_Klass_Text1:IsChecked() and true) or false;
        XBar["KlassV1"]=                        (XBarCfg_B_Klass_Value1:GetText()) or "[MCLASS]: [MLVL]";
        XBar["KlassT2"]=                        (XBarCfg_B_Klass_Text2:IsChecked() and true) or false;
        XBar["KlassV2"]=                        (XBarCfg_B_Klass_Value2:GetText()) or "[SCLASS]: [SLVL]";
        XBar["Mail"]=                                (XBarCfg_B_Mail_Show:IsChecked() and true) or false;
        XBar["MailT1"]=                        (XBarCfg_B_Mail_Text1:IsChecked() and true) or false;
        XBar["MailV1"]=                        (XBarCfg_B_Mail_Value1:GetText()) or "New: [UNREAD]";
        XBar["MailT2"]=                        (XBarCfg_B_Mail_Text2:IsChecked() and true) or false;
        XBar["MailV2"]=                        (XBarCfg_B_Mail_Value2:GetText()) or "";
        XBar["Money"]=                                (XBarCfg_B_Money_Show:IsChecked() and true) or false;
        XBar["MoneyT1"]=                        (XBarCfg_B_Money_Text1:IsChecked() and true) or false;
        XBar["MoneyV1"]=                        (XBarCfg_B_Money_Value1:GetText()) or "Gold: [GOLD]";
        XBar["MoneyT2"]=                        (XBarCfg_B_Money_Text2:IsChecked() and true) or false;
        XBar["MoneyV2"]=                        (XBarCfg_B_Money_Value2:GetText()) or "Dias: [DIAS]";
        XBar["Ping"]=                                (XBarCfg_B_Ping_Show:IsChecked() and true) or false;
        XBar["PingT1"]=                        (XBarCfg_B_Ping_Text1:IsChecked() and true) or false;
        XBar["PingV1"]=                        (XBarCfg_B_Ping_Value1:GetText()) or "ms: [MS]";
        XBar["PingT2"]=                        (XBarCfg_B_Ping_Text2:IsChecked() and true) or false;
        XBar["PingV2"]=                        (XBarCfg_B_Ping_Value2:GetText()) or "Fps: [FPS]";
        XBar["PF"]=                                        (XBarCfg_X_PF_CB:IsChecked() and true) or false;
        XBar["PF_Anchor"]=                (XBarCfg_X_PF_XA:IsChecked() and true) or false;
        XBar["PF_X"]=                                (tonumber(XBarCfg_X_PF_X:GetText()) or 0);
        XBar["PF_Y"]=                                (tonumber(XBarCfg_X_PF_Y:GetText()) or 23);
        XBar["TF"]=                                        (XBarCfg_X_TF_CB:IsChecked() and true) or false;
        XBar["TF_Anchor"]=                (XBarCfg_X_TF_XA:IsChecked() and true) or false;
        XBar["TF_X"]=                                (tonumber(XBarCfg_X_TF_X:GetText()) or 392);
        XBar["TF_Y"]=                                (tonumber(XBarCfg_X_TF_Y:GetText()) or 23);
        XBar["TT"]=                                        (XBarCfg_X_TT_CB:IsChecked() and true) or false;
        XBar["TT_Anchor"]=                (XBarCfg_X_TT_XA:IsChecked() and true) or false;
        XBar["TT_X"]=                                (tonumber(XBarCfg_X_TT_X:GetText()) or 540);
        XBar["TT_Y"]=                                (tonumber(XBarCfg_X_TT_Y:GetText()) or 23);
        XBar["BF"]=                                        (XBarCfg_X_BF_CB:IsChecked() and true) or false;
        XBar["BF_Anchor"]=                (XBarCfg_X_BF_XA:IsChecked() and true) or false;
        XBar["BF_X"]=                                (tonumber(XBarCfg_X_BF_X:GetText()) or 600);
        XBar["BF_Y"]=                                (tonumber(XBarCfg_X_BF_Y:GetText()) or 23);
        XBar["DB"]=                                        (XBarCfg_X_DB_CB:IsChecked() and true) or false;
        XBar["DB_Anchor"]=                (XBarCfg_X_DB_XA:IsChecked() and true) or false;
        XBar["DB_X"]=                                (tonumber(XBarCfg_X_DB_X:GetText()) or 600);
        XBar["DB_Y"]=                                (tonumber(XBarCfg_X_DB_Y:GetText()) or 55);
        XBar["CB"]=                                        (XBarCfg_X_CB_CB:IsChecked() and true) or false;
        XBar["CB_Anchor"]=                (XBarCfg_X_CB_XA:IsChecked() and true) or false;
        XBar["CB_X"]=                                (tonumber(XBarCfg_X_CB_X:GetText()) or 600);
        XBar["CB_Y"]=                                (tonumber(XBarCfg_X_CB_Y:GetText()) or 55);
        XBar["XP"]=                                        (XBarCfg_X_XP_CB:IsChecked() and true) or false;
        XBar["XP_Anchor"]=                (XBarCfg_X_XP_XA:IsChecked() and true) or false;
        XBar["XP_Xs"]=                                (tonumber(XBarCfg_X_XP_Xs:GetText()) or 100);
        XBar["XP_Ys"]=                                (tonumber(XBarCfg_X_XP_Ys:GetText()) or 32);
        XBar["XP_Xe"]=                                (tonumber(XBarCfg_X_XP_Xe:GetText()) or -100);
        XBar["XP_Ye"]=                                (tonumber(XBarCfg_X_XP_Ye:GetText()) or 32);
        XBar["XP_H"]=                                (tonumber(XBarCfg_X_XP_H:GetText()) or 13);
        XBar["PT"]=                                        (XBarCfg_X_PT_CB:IsChecked() and true) or false;
        XBar["PT_Anchor"]=                (XBarCfg_X_PT_XA:IsChecked() and true) or false;
        XBar["PT_X"]=                                (tonumber(XBarCfg_X_PT_X:GetText()) or 0);
        XBar["PT_Y"]=                                (tonumber(XBarCfg_X_PT_Y:GetText()) or 100);
        XBar["RF"]=                                        (XBarCfg_X_PF_CB:IsChecked() and true) or false;
        XBar["RF_Anchor"]=                (XBarCfg_X_PF_XA:IsChecked() and true) or false;
        XBar["RF_X"]=                                (tonumber(XBarCfg_X_RF_X:GetText()) or 15);
        XBar["RF_Y"]=                                (tonumber(XBarCfg_X_RF_Y:GetText()) or 120);
        XBar["MF"]=                                        (XBarCfg_X_MF_CB:IsChecked() and true) or false;
        XBar["MF_Anchor"]=                (XBarCfg_X_MF_XA:IsChecked() and true) or false;
        XBar["MF_X"]=                                (tonumber(XBarCfg_X_MF_X:GetText()) or 690);
        XBar["MF_Y"]=                                (tonumber(XBarCfg_X_MF_Y:GetText()) or 23);
        XBar["MF_Time"]=                        (XBarCfg_X_MF_Time_CB:IsChecked() and true) or false;
        XBar["MF_Time_Anchor"]=        (XBarCfg_X_MF_Time_XA:IsChecked() and true) or false;
        XBar["MF_Time_X"]=                (tonumber(XBarCfg_X_MF_Time_X:GetText()) or 690);
        XBar["MF_Time_Y"]=                (tonumber(XBarCfg_X_MF_Time_Y:GetText()) or 23);
        XBar["MF_Title"]=                        (XBarCfg_X_MF_Title_CB:IsChecked() and true) or false;
        XBar["MF_Title_Anchor"]=(XBarCfg_X_MF_Title_XA:IsChecked() and true) or false;
        XBar["MF_Title_X"]=                (XBarCfg_X_MF_Title_X:GetText()) or "690";
        XBar["MF_Title_Y"]=                (XBarCfg_X_MF_Title_Y:GetText()) or "32";
        XBar["MF_Double"]=                (XBarCfg_X_MF_DblXFrame:IsChecked() and true) or false;
        XBar["MF_Style"]=                        (UIDropDownMenu_GetSelectedID(XBarCfg_X_MF_Style));
        XBar["MF_Size"]=                        (XBarCfg_X_MF_Size:GetText());
        XBar["MF_Buttons"]=                (XBarCfg_X_MF_Buttons:IsChecked() and true) or false;
        XBar["HF"]=                                        (XBarCfg_X_HF_CB:IsChecked() and true) or false;
        XBar["HF_Anchor"]=                (XBarCfg_X_HF_XA:IsChecked() and true) or false;
        XBar["HF_X"]=                                (tonumber(XBarCfg_X_HF_X:GetText()) or 0);
        XBar["HF_Y"]=                                (tonumber(XBarCfg_X_HF_Y:GetText()) or 23);
        XBar["CF"]=                                        (XBarCfg_X_CF_CB:IsChecked() and true) or false;
        XBar["CF_Anchor"]=                (XBarCfg_X_CF_XA:IsChecked() and true) or false;
        XBar["CF_X"]=                                (tonumber(XBarCfg_X_CF_X:GetText()) or 0);
        XBar["CF_Y"]=                                (tonumber(XBarCfg_X_CF_Y:GetText()) or 500);
        DEFAULT_CHAT_FRAME:AddMessage(XLng["Chat"]["saved"],.5,1,.5);
        XBarAmmo_OnEvent();
        XBarBag_OnEvent();
        XBarExp_OnEvent();
        XBarFriend_OnEvent();
        XBarGuild_OnEvent();
        XBarKlass_OnEvent();
        XBarMoney_OnEvent();
        XBar_OnEvent(this,"VARIABLES_LOADED",true);
end

function XBarCfg_BarDesign_OnLoad()
        for i,s in pairs(xdsgn) do UIDropDownMenu_AddButton({["text"]=s,["func"]=XBarCfg_BarDesign_OnClick}); end
end

function XBarCfg_BarDesign_OnClick(selection)
    UIDropDownMenu_SetSelectedID(XBarCfg_G_Style,selection:GetID());
end

function XBarCfg_MapDesign_OnLoad()
        for i,s in pairs(mdsgn) do UIDropDownMenu_AddButton({["text"]=s,["func"]=XBarCfg_MapDesign_OnClick}); end
end

function XBarCfg_MapDesign_OnClick(selection)
    UIDropDownMenu_SetSelectedID(XBarCfg_X_MF_Style,selection:GetID());
end

function XBarCfg_SetPos(button)
        if (button==1) then
                XBarCfg_G_CB_XE_T:SetChecked(1);
                XBarCfg_G_CB_XE_B:SetChecked(nil);
        else
                XBarCfg_G_CB_XE_T:SetChecked(nil);
                XBarCfg_G_CB_XE_B:SetChecked(1);
        end
end

function XBarCfg_Slider_Init(this)
        this:SetValueStepMode("FLOAT");
        this:SetMinMaxValues(0,1);
        this:SetValue(1);
end

function XBarCfg_Slider_OnValueChanged(this)
        local value=this:GetValue();
        if (this:GetValueStepMode()=="FLOAT") then value=string.format("%.2f",value); end
        getglobal(this:GetName().."Value"):SetText(value*100);
end

function XBarCfg_Alpha_OnValueChanged(this)
        local value=this:GetValue();
        if (this:GetValueStepMode()=="FLOAT") then value=string.format("%.2f",value); end
        getglobal(this:GetName().."Value"):SetText(value);
--        if (XLng["Config"]) then getglobal(this:GetName().."Name"):SetText(XLng["Config"]["Lucid"]);
--        else getglobal(this:GetName().."Name"):SetText("Transparency : "); end
        XBarFrame:SetAlpha(value);
        XBar["Alpha"]=value;
end

function XBarCfg_ScrollLegend_OnShow(this,frame)
        local Head=XLng["Legend"]["Head2"];
        if (frame) then XBarCfg_ScrollLegend.frame=frame; end
        for i=1,15 do getglobal("XBarCfg_ScrollLegend_Button"..i):Hide(); end
        if (XBarCfg_ScrollLegend.frame=="SPAM") then
                for i=1,15 do
                        if (XBar["Spamlist"][XBarCfg_ScrollLegend.start+i-1]) then
                                getglobal("XBarCfg_ScrollLegend_Button"..i.."Text"):SetText("["..XBar["Spamlist"][XBarCfg_ScrollLegend.start+i-1].."]");
                                getglobal("XBarCfg_ScrollLegend_Button"..i):SetID(i);
                                getglobal("XBarCfg_ScrollLegend_Button"..i):Show();
                        end
                end
        end
        XBarCfg_ScrollLegend:Show();
        XBarCfg_ScrollLegend_Head:SetText(Head);
end

function XBarCfg_ScrollLegend_OnWheel(this,delta)
        local start=XBarCfg_ScrollLegend.start;
        if (delta>0) then if (start>1) then start=start-1; end; end
        if (delta<0) then if (start<#XBar["Spamlist"]-14) then start=start+1; end; end
        XBarCfg_ScrollLegend.start=start;
        XBarCfg_ScrollLegend_OnShow(this);
end

function XBarCfg_ScrollLegend_OnClick(this,key)
        local ID=this:GetID();
        for i=1,15 do getglobal("XBarCfg_ScrollLegend_Button"..i.."Mark"):Hide(); end
        getglobal(this:GetName().."Mark"):Show();
        XBarCfg_Spam_Edit:SetText(XBar["Spamlist"][ID]);
        XBarCfg_Spam_Del:Show();
        XBarCfg_Spam_Esc:Show();
        XBarCfg_ScrollLegend_OnShow();
end

function XBarCfg_SpamAdd(this)
        local exist=0;
        for i=1,#XBar["Spamlist"] do
                if (XBarCfg_Spam_Edit:GetText()==XBar["Spamlist"][i]) then exist=1; end;
        end
        if (exist==0) then table.insert (XBar["Spamlist"],1,XBarCfg_Spam_Edit:GetText()); end
        XBarCfg_Spam_Edit:SetText("");
        XBarCfg_Spam_Del:Hide();
        XBarCfg_Spam_Esc:Hide();
        for i=1,15 do getglobal("XBarCfg_ScrollLegend_Button"..i.."Mark"):Hide(); end
        XBarCfg_ScrollLegend_OnShow();
end

function XBarCfg_SpamDel(this)
        for i,value in ipairs(XBar["Spamlist"]) do
                if (value==XBarCfg_Spam_Edit:GetText()) then table.remove (XBar["Spamlist"],i) end
        end
        XBarCfg_Spam_Edit:SetText("");
        XBarCfg_Spam_Del:Hide();
        XBarCfg_Spam_Esc:Hide();
        for i=1,15 do getglobal("XBarCfg_ScrollLegend_Button"..i.."Mark"):Hide(); end
        XBarCfg_ScrollLegend_OnShow();
end

function XBarCfg_Legend_OnShow(frame)
        local Head=XLng["Legend"]["Head"];
        local Keys="";
        if (frame=="Ammo") then
                Keys=Keys.."|cff76C776[AMMO]|r\n|cff767676"..XLng["Legend"]["Ammo1"].."|r\n";
        elseif (frame=="Bag") then
                Keys=Keys.."|cff76C776[USED]|r\n|cff767676"..XLng["Legend"]["Bag1"].."|r\n";
                Keys=Keys.."|cff76C776[TOTAL]|r\n|cff767676"..XLng["Legend"]["Bag2"].."|r\n";
                Keys=Keys.."|cff76C776[LOAD]|r\n|cff767676"..XLng["Legend"]["Bag3"].."|r\n";
        elseif (frame=="Clock") then
                Keys=Keys.."|cff76C776[TIME12]|r\n|cff767676"..XLng["Legend"]["Clock1"].."|r\n";
                Keys=Keys.."|cff76C776[TIME24]|r\n|cff767676"..XLng["Legend"]["Clock2"].."|r\n";
                Keys=Keys.."|cff76C776[DATE]|r\n|cff767676"..XLng["Legend"]["Clock3"].."|r\n";
                Keys=Keys.."|cff76C776[ONLINE]|r\n|cff767676"..XLng["Legend"]["Clock4"].."|r\n";
                Keys=Keys.."|cff76C776[TOTALONLINE]|r\n|cff767676"..XLng["Legend"]["Clock5"].."|r\n";
        elseif (frame=="Dps") then
                Keys=Keys.."|cff76C776[DPS]|r\n|cff767676"..XLng["Legend"]["Dps1"].."|r\n";
                Keys=Keys.."|cff76C776[KILLS]|r\n|cff767676"..XLng["Legend"]["Dps2"].."|r\n";
                Keys=Keys.."|cff76C776[DMG]|r\n|cff767676"..XLng["Legend"]["Dps3"].."|r\n";
        elseif (frame=="Exp") then
                Keys=Keys.."|cff76C776[XP]|r|cff767676"..XLng["Legend"]["Exp1"].."|r\n";
                Keys=Keys.."|cff76C776[TP]|r|cff767676"..XLng["Legend"]["Exp2"].."|r\n";
                Keys=Keys.."|cff76C776[XPNEED]|r\n|cff767676"..XLng["Legend"]["Exp3"].."|r\n";
                Keys=Keys.."|cff76C776[XPFULL]|r\n|cff767676"..XLng["Legend"]["Exp4"].."|r\n";
                Keys=Keys.."|cff76C776[PERCENT]|r\n|cff767676"..XLng["Legend"]["Exp5"].."|r\n";
                Keys=Keys.."|cff76C776[PERCENTNEED]|r\n|cff767676"..XLng["Legend"]["Exp6"].."|r\n";
                Keys=Keys.."|cff76C776[XPBONUS]|r|cff767676"..XLng["Legend"]["Exp7"].."|r\n";
                Keys=Keys.."|cff76C776[TPBONUS]|r|cff767676"..XLng["Legend"]["Exp8"].."|r\n";
                Keys=Keys.."|cff76C776[XPDEPT]|r|cff767676"..XLng["Legend"]["Exp9"].."|r\n";
                Keys=Keys.."|cff76C776[TPDEPT]|r|cff767676"..XLng["Legend"]["Exp10"].."|r\n";
                Keys=Keys.."|cff76C776[XPLAST]|r\n|cff767676"..XLng["Legend"]["Exp11"].."|r\n";
                Keys=Keys.."|cff76C776[TPLAST]|r\n|cff767676"..XLng["Legend"]["Exp12"].."|r\n";
                Keys=Keys.."|cff76C776[XPSESSION]|r\n|cff767676"..XLng["Legend"]["Exp13"].."|r\n";
                Keys=Keys.."|cff76C776[TPSESSION]|r\n|cff767676"..XLng["Legend"]["Exp14"].."|r\n";
                Keys=Keys.."|cff76C776[XPREPEATS]|r\n|cff767676"..XLng["Legend"]["Exp15"].."|r\n";
        elseif (frame=="Friend") then
                Keys=Keys.."|cff76C776[ONLINE]|r\n|cff767676"..XLng["Legend"]["Friend1"].."|r\n";
                Keys=Keys.."|cff76C776[COUNT]|r\n|cff767676"..XLng["Legend"]["Friend2"].."|r\n";
        elseif (frame=="Guild") then
                Keys=Keys.."|cff76C776[GNAME]|r\n|cff767676"..XLng["Legend"]["Guild1"].."|r\n";
                Keys=Keys.."|cff76C776[GLVL]|r\n|cff767676"..XLng["Legend"]["Guild2"].."|r\n";
                Keys=Keys.."|cff76C776[GLEADER]|r\n|cff767676"..XLng["Legend"]["Guild3"].."|r\n";
                Keys=Keys.."|cff76C776[ONLINE]|r\n|cff767676"..XLng["Legend"]["Guild4"].."|r\n";
                Keys=Keys.."|cff76C776[MEMBER]|r\n|cff767676"..XLng["Legend"]["Guild5"].."|r\n";
                Keys=Keys.."|cff76C776[MAX]|r\n|cff767676"..XLng["Legend"]["Guild6"].."|r\n";
                Keys=Keys.."|cff76C776[RIGHT]|r\n|cff767676"..XLng["Legend"]["Guild7"].."|r\n";
        elseif (frame=="Klass") then
                Keys=Keys.."|cff76C776[MCLASS]|r\n|cff767676"..XLng["Legend"]["Klass1"].."|r\n";
                Keys=Keys.."|cff76C776[MLVL]|r\n|cff767676"..XLng["Legend"]["Klass2"].."|r\n";
                Keys=Keys.."|cff76C776[SCLASS]|r\n|cff767676"..XLng["Legend"]["Klass3"].."|r\n";
                Keys=Keys.."|cff76C776[SLVL]|r\n|cff767676"..XLng["Legend"]["Klass4"].."|r\n";
        elseif (frame=="Mail") then
                Keys=Keys.."|cff76C776[UNREAD]|r\n|cff767676"..XLng["Legend"]["Mail1"].."|r\n";
        elseif (frame=="Money") then
                Keys=Keys.."|cff76C776[GOLD]|r\n|cff767676"..XLng["Legend"]["Money1"].."|r\n";
                Keys=Keys.."|cff76C776[DIAS]|r\n|cff767676"..XLng["Legend"]["Money2"].."|r\n";
                Keys=Keys.."|cff76C776[RUBY]|r\n|cff767676"..XLng["Legend"]["Money3"].."|r\n";
                Keys=Keys.."|cff76C776[COIN]|r\n|cff767676"..XLng["Legend"]["Money4"].."|r\n";
        elseif (frame=="Ping") then
                Keys=Keys.."|cff76C776[MS]|r\n|cff767676"..XLng["Legend"]["Ping1"].."|r\n";
                Keys=Keys.."|cff76C776[FPS]|r\n|cff767676"..XLng["Legend"]["Ping2"].."|r\n";
        end
        XBarCfg_Legend:Show();
        XBarCfg_Legend_Head:SetText(Head);
        XBarCfg_Legend_Keys:SetText(Keys);
end

-- #################################################################################################################
-- XAddon Manager
-- #################################################################################################################
-------------------------------------------------------------------------------------
--[[
function CRG_OpenColorPick(this)

        local texture=getglobal(this:GetName().."Texture");
        local r,g,b=texture:GetColor();
        local a=1.0;
                        ColorPickerFrame.call=this;
                        OpenColorPickerFrame(CRF_PickerColor,nil,nil,r,g,b,a,this);

end
-------------------------------------------------------------------------------------
function CRF_PickerColor()

        this=ColorPickerFrame.call;
        local frame=this:GetParent():GetParent();

        local info=frame.info;

        local texture=getglobal(this:GetName().."Texture");

        info.r=ColorPickerFrame.r*255;
        info.g=ColorPickerFrame.g*255;
        info.b=ColorPickerFrame.b*255;
        texture:SetColor(ColorPickerFrame.r, ColorPickerFrame.g,ColorPickerFrame.b);

        CRF_SaveChatInfo();

end
]]
------------------------------------------------------------------------------------------------
function XAddonMngr_OnShow(this)
        if (XAddons.window) then getglobal(XAddons.window):Hide(); end
         XAddonMngr_Header_Name:SetText("XAddon Manager");
         XAddonMngr_Header_Version:SetText("alpha preview");
         XAddonMngr_Info_Title:SetText(XLng["XAddon"]["Title"]);
         XAddonMngr_Info_Preamble:SetText(XLng["XAddon"]["Pre"]);
         XAddonMngr_Info_Description:SetText(XLng["XAddon"]["Descr"]);
         XAddonMngr_Info:Show();
        XBarCfg_SaveButton:SetText(XLng["Config"]["Save"]);
        XBarCfg_G_CB_XE_Text:SetText(XLng["Config"]["EnableXBar"]);
        XBarCfg_G_CB_XE_T_Text:SetText(XLng["Config"]["Top"]);
        XBarCfg_G_CB_XE_B_Text:SetText(XLng["Config"]["Bottom"]);
        XBarCfg_G_CB_MB_Text:SetText(XLng["Config"]["ShowMenuBtn"]);
        XBarCfg_G_Style_Text:SetText(XLng["Config"]["Style"]);
        XBarCfg_G_CB_MF_Text:SetText(XLng["Config"]["HideOriginalMenu"]);
        XBarCfg_G_CB_EF_Text:SetText(XLng["Config"]["HideOriginalXP"]);
        XBarCfg_G_CB_DF_Text:SetText(XLng["Config"]["HideOriginalED"]);
        XBarCfg_G_SR_Alpha_Text:SetText(XLng["Config"]["Lucid"]);
        XBarCfg_Afk_Enable_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_Afk_KeepMsg_Text:SetText(XLng["Config"]["KeepMsg"]);
        XBarCfg_Afk_AutoAfk_Text:SetText(XLng["Config"]["AutoAfk"]);
        XBarCfg_Afk_Timer_Text:SetText(XLng["Config"]["Timer"]);
        XBarCfg_Afk_KeepAfk_Text:SetText(XLng["Config"]["KeepAfk"]);
        XBarCfg_Afk_Value1_Text:SetText(XLng["Config"]["AfkValue1"]);
        XBarCfg_Afk_Value2_Text:SetText(XLng["Config"]["AfkValue2"]);
        XBarCfg_Spam_Enable_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_Spam_Edit_Text:SetText(XLng["Config"]["SpamCheck"]);
        XBarCfg_Spam_Add:SetText(XLng["Config"]["Insert"]);
        XBarCfg_Spam_Esc:SetText(XLng["Config"]["Cancel"]);
        XBarCfg_Spam_Del:SetText(XLng["Config"]["Delete"]);
        XBarCfg_B_Bag_Show_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_B_Bag_Text1_Text:SetText(XLng["Config"]["Text1"]);
        XBarCfg_B_Bag_Text2_Text:SetText(XLng["Config"]["Text2"]);
        XBarCfg_B_Bag_Value1_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Bag_Value2_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Mail_Show_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_B_Money_Show_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_B_Ammo_Show_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_B_Exp_Show_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_B_Klass_Show_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_B_Ping_Show_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_B_Dps_Show_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_B_Guild_Show_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_B_Friend_Show_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_B_Clock_Show_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_X_PF_CB_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_X_TF_CB_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_X_TT_CB_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_X_BF_CB_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_X_DB_CB_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_X_CB_CB_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_X_XP_CB_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_X_PT_CB_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_X_RF_CB_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_X_MF_CB_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_X_HF_CB_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_X_CF_CB_Text:SetText(XLng["Config"]["Enable"]);
        XBarCfg_B_Mail_Text1_Text:SetText(XLng["Config"]["Text1"]);
        XBarCfg_B_Money_Text1_Text:SetText(XLng["Config"]["Text1"]);
        XBarCfg_B_Ammo_Text1_Text:SetText(XLng["Config"]["Text1"]);
        XBarCfg_B_Exp_Text1_Text:SetText(XLng["Config"]["Text1"]);
        XBarCfg_B_Klass_Text1_Text:SetText(XLng["Config"]["Text1"]);
        XBarCfg_B_Ping_Text1_Text:SetText(XLng["Config"]["Text1"]);
        XBarCfg_B_Dps_Text1_Text:SetText(XLng["Config"]["Text1"]);
        XBarCfg_B_Guild_Text1_Text:SetText(XLng["Config"]["Text1"]);
        XBarCfg_B_Friend_Text1_Text:SetText(XLng["Config"]["Text1"]);
        XBarCfg_B_Clock_Text1_Text:SetText(XLng["Config"]["Text1"]);
        XBarCfg_B_Mail_Text2_Text:SetText(XLng["Config"]["Text2"]);
        XBarCfg_B_Money_Text2_Text:SetText(XLng["Config"]["Text2"]);
        XBarCfg_B_Ammo_Text2_Text:SetText(XLng["Config"]["Text2"]);
        XBarCfg_B_Exp_Text2_Text:SetText(XLng["Config"]["Text2"]);
        XBarCfg_B_Klass_Text2_Text:SetText(XLng["Config"]["Text2"]);
        XBarCfg_B_Ping_Text2_Text:SetText(XLng["Config"]["Text2"]);
        XBarCfg_B_Dps_Text2_Text:SetText(XLng["Config"]["Text2"]);
        XBarCfg_B_Guild_Text2_Text:SetText(XLng["Config"]["Text2"]);
        XBarCfg_B_Friend_Text2_Text:SetText(XLng["Config"]["Text2"]);
        XBarCfg_B_Clock_Text2_Text:SetText(XLng["Config"]["Text2"]);
        XBarCfg_B_Mail_Value1_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Money_Value1_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Ammo_Value1_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Exp_Value1_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Klass_Value1_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Ping_Value1_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Dps_Value1_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Guild_Value1_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Friend_Value1_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Mail_Value2_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Money_Value2_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Ammo_Value2_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Exp_Value2_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Klass_Value2_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Ping_Value2_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Dps_Value2_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Guild_Value2_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Friend_Value2_Text:SetText(XLng["Config"]["Value"]);
        XBarCfg_B_Clock_Value1_Text:SetText(XLng["Config"]["ValueL1"]);
        XBarCfg_B_Clock_Value2_Text:SetText(XLng["Config"]["ValueL2"]);
        XBarCfg_B_Clock_Value3_Text:SetText(XLng["Config"]["ValueR"]);
        XBarCfg_B_Clock_Value4_Text:SetText(XLng["Config"]["ValueSL1"]);
        XBarCfg_B_Clock_Value5_Text:SetText(XLng["Config"]["ValueSL2"]);
        XBarCfg_X_PF_XA_Text:SetText(XLng["Config"]["Anchor"]);
        XBarCfg_X_TF_XA_Text:SetText(XLng["Config"]["Anchor"]);
        XBarCfg_X_TT_XA_Text:SetText(XLng["Config"]["Anchor"]);
        XBarCfg_X_BF_XA_Text:SetText(XLng["Config"]["Anchor"]);
        XBarCfg_X_DB_XA_Text:SetText(XLng["Config"]["Anchor"]);
        XBarCfg_X_CB_XA_Text:SetText(XLng["Config"]["Anchor"]);
        XBarCfg_X_XP_XA_Text:SetText(XLng["Config"]["Anchor"]);
        XBarCfg_X_PT_XA_Text:SetText(XLng["Config"]["Anchor"]);
        XBarCfg_X_RF_XA_Text:SetText(XLng["Config"]["Anchor"]);
        XBarCfg_X_MF_XA_Text:SetText(XLng["Config"]["Anchor"]);
        XBarCfg_X_MF_Title_XA_Text:SetText(XLng["Config"]["Anchor"]);
        XBarCfg_X_MF_Time_XA_Text:SetText(XLng["Config"]["Anchor"]);
        XBarCfg_X_HF_XA_Text:SetText(XLng["Config"]["Anchor"]);
        XBarCfg_X_CF_XA_Text:SetText(XLng["Config"]["Anchor"]);
        XBarCfg_X_BF_Dummy:SetText(XLng["Config"]["Dummy"]);
        XBarCfg_X_DB_Dummy:SetText(XLng["Config"]["Dummy"]);
        XBarCfg_X_CB_Dummy:SetText(XLng["Config"]["Dummy"]);
        XBarCfg_X_PT_Dummy:SetText(XLng["Config"]["Dummy"]);
        XBarCfg_X_RF_Dummy:SetText(XLng["Config"]["Dummy"]);
        XBarCfg_X_HF_Dummy:SetText(XLng["Config"]["Dummy"]);
        XBarCfg_X_XP_Xs_Text:SetText(XLng["Config"]["Xleft"]);
        XBarCfg_X_XP_Ys_Text:SetText(XLng["Config"]["Yleft"]);
        XBarCfg_X_XP_Xe_Text:SetText(XLng["Config"]["Xright"]);
        XBarCfg_X_XP_Ye_Text:SetText(XLng["Config"]["Yright"]);
        XBarCfg_X_XP_H_Text:SetText(XLng["Config"]["Height"]);
        XBarCfg_X_MF_DblXFrame_Text:SetText(XLng["Config"]["DblAnchor"]);
        XBarCfg_X_MF_Size_Text:SetText(XLng["Config"]["Size"]);
        XBarCfg_X_MF_Style_Text:SetText(XLng["Config"]["Style"]);
        XBarCfg_X_MF_Buttons_Text:SetText(XLng["Config"]["Buttons"]);
        XBarCfg_X_MF_Title_CB_Text:SetText(XLng["Config"]["Zone"]);
        XBarCfg_X_MF_Time_CB_Text:SetText(XLng["Config"]["Time"]);
        for index,value in pairs(XAddons) do if (value.open) then value.open=false; end; end
         XAddonMngr_ListButton_Update(this);
end

function XAddonMngr_OnUpdate(this)
        if (XAddonMngr.fadeMode==1) then
                return;
        elseif (XAddonMngr.fadeMode==2) then
                XAddonMngr.fadeTimer=XAddonMngr.fadeTimer-0.1;
                if (XAddonMngr.fadeTimer<0) then
                        XAddonMngr.fadeMode=1;
                        XAddonMngr.fadeTimer=0;
                        XAddonMngr:Hide();
                end
                XAddonMngr:SetAlpha(XAddonMngr.fadeTimer); XAddonMngr:SetScale(XAddonMngr.fadeTimer);
        elseif (XAddonMngr.fadeMode==3) then
                XAddonMngr.fadeTimer=XAddonMngr.fadeTimer+0.1;
                if (XAddonMngr.fadeTimer>1) then
                        XAddonMngr.fadeMode=1;
                        XAddonMngr.fadeTimer=1;
                        XAddonMngr:Show();
                end
                XAddonMngr:SetAlpha(XAddonMngr.fadeTimer); XAddonMngr:SetScale(XAddonMngr.fadeTimer);
        end
end

function XAddonMngr_Toggle(this)
        if (XAddonMngr:IsVisible()) then XAddonMngr.fadeMode=2; XAddonMngr.fadeTimer=1;
        else XAddonMngr:Show(); XAddonMngr.fadeMode=3; XAddonMngr.fadeTimer=0; end
end

--[[function XAddonMngr_Help_OnClick(this)
end]]

function XAddonMngr_ListButton_OnClick(this,key)
        local selected=this:GetID();
        for index,value in pairs(XAddons) do
                if (value.type=="MainMenu" or value.type=="SubMenu") and (not value.children) then value.open=false; end
                if (value.type=="ItemBtn") then value.open=false; end
        end
        if (XAddons.window) then getglobal(XAddons.window):Hide(); end
        if (XAddons[selected].window) then XAddons.window=XAddons[selected].window; end
        if (XAddons[selected].title) then XAddons.title=XAddons[selected].title; end
        if (XAddons[selected].version) then XAddons.version=XAddons[selected].version; end
        if (XAddons[selected].type=="TopMenu") then
                if (XAddons[selected].OnClick) then XAddons[selected].OnClick(); end
        end
        if (XAddons[selected].type=="SubMenu") then
                if (XAddons[selected].OnClick) then XAddons[selected].OnClick(); end
        end
        if (XAddons[selected].type=="ItemBtn") then
                if (XAddons[selected].OnClick) then XAddons[selected].OnClick(); end
        end
        if (XAddons[selected].open==true) then
                XAddons[selected].open=false;
                getglobal(XAddons.window):Hide();
                 XAddonMngr_Header_Name:SetText("XAddon Manager");
                 XAddonMngr_Header_Version:SetText("alpha preview");
                XAddonMngr_Info:Show();
        else
                XAddons[selected].open=true;
                getglobal(XAddons.window):Show();
                 XAddonMngr_Header_Name:SetText(XAddons.title);
                 XAddonMngr_Header_Version:SetText(XAddons.version);
                 XAddonMngr_Info:Hide();
        end
        XAddonMngr_ListButton_Update(this:GetID());
end

function XAddonMngr_ListButton_Update(nowid)
        local btn;
        local btn_width=135;
        local btn_text={r=1,g=1,b=1};
        local btn_list=0;
        local btn_count=1;
        local btn_temp=1;
        local showsub=false;
        local showitem=false;
        local value={};
        local start=XAddonMngr_Menu_ScrollBar:GetValue();
        XAddonMngr_Menu_ScrollBar:SetMaxValue(table.getn(XAddons));
        XAddonMngr_Menu_ScrollBar:SetMinValue(1);
        XAddonMngr_Menu_ScrollBar:Show();
        for i=1,20 do
                getglobal("XAddonMngr_List_Btn"..i):UnlockHighlight();
                getglobal("XAddonMngr_List_Btn"..i.."_OpenedArrow"):Hide();
                getglobal("XAddonMngr_List_Btn"..i.."_ExpandArrow"):Hide();
                getglobal("XAddonMngr_List_Btn"..i.."_Icon"):Hide();
                getglobal("XAddonMngr_List_Btn"..i):Hide();
        end
        for index,value in pairs(XAddons) do
                if (btn_count>20) then return; end
                btn=getglobal("XAddonMngr_List_Btn"..btn_count);
                if (value.type) then
                        if (value.type=="TopMenu") then
                                if (value.open) then
                                        showsub=true;
                                        showitem=true;
                                        if (value.children) then btn_text={r=.34,g=1,b=.34};
                                        else btn_text={r=.76,g=.76,b=.76}; end
                                else
                                        showsub=false;
                                        showitem=false;
                                        if (value.children) then btn_text={r=.34,g=.34,b=1};
                                        else btn_text={r=.76,g=.76,b=.76}; end
                                end
                                btn_width=135;
                                btn_list=btn_list+1;
                        elseif (value.type=="SubMenu" and showsub==true) then
                                if (value.open) then
                                        showitem=true;
                                        if (value.children) then btn_text={r=.34,g=1,b=.34};
                                        else btn_text={r=.76,g=.76,b=.76}; end
                                else
                                        showitem=false;
                                        if (value.children) then btn_text={r=.34,g=.34,b=1};
                                        else btn_text={r=.76,g=.76,b=.76}; end
                                end
                                btn_width=130;
                                btn_list=btn_list+1;
                        elseif (value.type=="ItemBtn" and showitem==true) then
                                if (value.open) then
                                        btn_text={r=.34,g=.76,b=.34};
                                else
                                        btn_text={r=.76,g=.76,b=.76};
                                end
                                btn_width=125;
                                btn_list=btn_list+1;
                        end
                end
                if (btn_list>=start) then
                        if (value.open and value.children) then btn:LockHighlight(); else btn:UnlockHighlight(); end
                        if (value.name) then btn:SetText(value.name); else btn:SetText("["..index.."]"); end
                        if (value.children) then
                                if (value.open) then
                                        getglobal(btn:GetName().."_OpenedArrow"):Show();
                                        getglobal(btn:GetName().."_ExpandArrow"):Hide();
                                else
                                        getglobal(btn:GetName().."_OpenedArrow"):Hide();
                                        getglobal(btn:GetName().."_ExpandArrow"):Show();
                                end
                        end
                        if (value.icon) then
                                getglobal(btn:GetName().."_ExpandArrow"):Hide();
                                getglobal(btn:GetName().."_OpenedArrow"):Hide();
                                getglobal(btn:GetName().."_Icon"):SetTexture(value.icon);
                                getglobal(btn:GetName().."_Icon"):Show();
                        end
                        if (value.type=="ItemBtn" and showitem==true) or (value.type=="SubMenu" and showsub==true) or (value.type=="TopMenu") then
                                if (index==nowid) then btn:SetTextColor(1,.34,.34);
                                else btn:SetTextColor(btn_text.r,btn_text.g,btn_text.b); end
                                btn:SetWidth(btn_width);
                                btn:SetID(index);
                                btn:Show();
                                btn_count=btn_count+1;
                        end
                end
        end
        if (btn_list<20) then
                XAddonMngr_Menu_ScrollBar:SetValue(0);
                XAddonMngr_Menu_ScrollBar:Hide();
        end
end
-- #################################################################################################################
-- XBar TOOLTIPS
-- #################################################################################################################
function XBar_Tooltip(this,name)
        if (name=="XFrame") then
                GameTooltip:SetOwner(this,"ANCHOR_BOTTOM",0,10);
                GameTooltip:SetText("XFrame v2",1,1,1);
                GameTooltip:AddLine(XLng["Ttip"]["SMOUSE_MOVE"],0,.7,.9);
        elseif (name=="Close") then
                GameTooltip:SetOwner(this,"ANCHOR_BOTTOM",0,10);
                GameTooltip:SetText("XBar III",1,1,1);
                GameTooltip:AddLine(XLng["Ttip"]["CLOSE_FRAME"],0,.7,.9);
        elseif (name=="Help") then
                GameTooltip:SetOwner(this,"ANCHOR_BOTTOM",0,10);
                GameTooltip:SetText("XBar III",1,1,1);
                GameTooltip:AddLine(XLng["Ttip"]["SHOW_HELP"].." (german)",0,.7,.9);
        else GameTooltip:Hide(); end
end
-- #################################################################################################################
-- XBar PopupMenu
-- #################################################################################################################
function XBar_PopupMenu_Toggle(parent,x,y,scroll)
        XBar_PopupMenu_SetPos(parent,x,y);
        if (XBar_PopupMenu:IsVisible()) then
                if (scroll==false) then XBar_PopupMenu:Hide();
                else XBar_PopupMenu:Hide(); XBar_PopupMenu:Show(); end
        else
                XBar_PopupMenu:Show();
        end
end

function XBar_PopupMenu_SetPos(parent,x,y)
        if (XBar["Position"]=="TOP") then
                XBar_PopupMenu:ClearAllAnchors(); XBar_PopupMenu:SetAnchor("TOPLEFT","TOPLEFT",parent,x,y);
        elseif (XBar["Position"]=="BOTTOM") then
                XBar_PopupMenu:ClearAllAnchors(); XBar_PopupMenu:SetAnchor("BOTTOMLEFT","BOTTOMLEFT",parent,x,-y);
        end
end

function XBar_PopupMenu_OnLoad(this)
        this:SetBackdropEdgeColor(.7,.7,.7);
        this:SetBackdropTileColor(0,0,0);
end

function XBar_PopupMenu_OnShow(this)
        this.showTimer=2; this.isCounting=1;
        XBar_PopupMenu_Update();
end

function XBar_PopupMenu_OnUpdate(this,elapsed)
        if (not this.showTimer or not this.isCounting) then return;
        elseif (this.showTimer<0) then this:Hide(); this.showTimer=nil;
        else this.showTimer=this.showTimer-elapsed; end
end

function XBar_PopupButton_OnWheel(this,delta)
        local info=XBar_PopupMenu.Buttons[this:GetID()];
        if (info.OnScroll) then info.OnScroll(delta); end
end

function XBar_PopupButton_OnClick(this,key)
        local info=XBar_PopupMenu.Buttons[this:GetID()];
        if (info.OnClick) then info.OnClick(this,key); end
        XBar_PopupMenu:Hide();
end

function XBar_PopupButton_OnEnter(this)
        PlaySoundByPath("sound\\interface\\ui_navbar_open.mp3");
        this:GetParent().isCounting=nil;
        local info=XBar_PopupMenu.Buttons[this:GetID()];
        if (info.GetTooltip) then
                local text=info.GetTooltip();
                if (text) then
                        GameTooltip:ClearAllAnchors();
                        GameTooltip:SetAnchor("TOPRIGHT","TOPLEFT",this,0,30);
                        GameTooltip:SetText(text);
                end
        end
end

function XBar_PopupButton_OnLeave(this)
        this:GetParent().showTimer=2;
        this:GetParent().isCounting=1;
        GameTooltip:Hide();
end

function XBar_PopupMenu_Update()
        local button;
        for index=1,15,1 do button=getglobal("XBar_PopupMenu_Button"..index); button:Hide(); end
        for index,value in pairs(XBar_PopupMenu.Buttons) do
                button=getglobal("XBar_PopupMenu_Button"..index);
                getglobal(button:GetName().."Icon"):SetTexture(value.icon);
                getglobal(button:GetName().."Text"):SetText(value.GetText());
                button:Show();
        end
        XBar_PopupMenu:SetHeight(20+(table.getn(XBar_PopupMenu.Buttons)*22));
end
-- #################################################################################################################
-- XBar Final Voice
-- #################################################################################################################
function DEFAULT_CHAT_FRAME:AddMessage(message,r,g,b)
        if (XBar["Spamlist"]) then
                if (XBar["Spam"]==true) then
                        for i=1,#XBar["Spamlist"] do
                                if (string.find(string.lower(message),XBar["Spamlist"][i])) then index=1; end
                        end
                        if not index then orig(obj,message,r,g,b); end
                        index=nil;
                else orig(obj,message,r,g,b); end
        end
end

function XBar_OnError(v1,v2,v3,v4,v5,v6,v7,v8,v9)
        local var={};
        if (v1) then var[1]="V1: |cffFFFFFF"..tostring(v1).."|r, "; else var[1]="V1: -.-, "; end
        if (v2) then var[1]="V2: |cffFFFFFF"..tostring(v2).."|r, "; else var[2]="V2: -.-, "; end
        if (v3) then var[1]="V3: |cffFFFFFF"..tostring(v3).."|r, "; else var[3]="V3: -.-, "; end
        if (v4) then var[1]="V4: |cffFFFFFF"..tostring(v4).."|r, "; else var[4]="V4: -.-, "; end
        if (v5) then var[1]="V5: |cffFFFFFF"..tostring(v5).."|r, "; else var[5]="V5: -.-, "; end
        if (v6) then var[1]="V6: |cffFFFFFF"..tostring(v6).."|r, "; else var[6]="V6: -.-, "; end
        if (v7) then var[1]="V7: |cffFFFFFF"..tostring(v7).."|r, "; else var[7]="V7: -.-, "; end
        if (v8) then var[1]="V8: |cffFFFFFF"..tostring(v8).."|r, "; else var[8]="V8: -.-, "; end
        if (v9) then var[1]="V9: |cffFFFFFF"..tostring(v9).."|r, "; else var[9]="V9: -.-, "; end
        DEFAULT_CHAT_FRAME:AddMessage("|cffFF0000"..var[1]..var[2]..var[3]..var[4]..var[5]..var[6]..var[7]..var[8]..var[9].."|r");
end

function XBar_SlashHandler(msg)
                msg=string.lower(msg);
                if (msg=="") or (msg=="h") or (msg=="hilfe") or (msg=="help") then
                        DEFAULT_CHAT_FRAME:AddMessage(XLng["Chat"]["help"],1,1,1);
                        DEFAULT_CHAT_FRAME:AddMessage(XLng["Chat"]["toggle_xbar"],.5,.5,.5);
                        DEFAULT_CHAT_FRAME:AddMessage(XLng["Chat"]["toggle_main"],.5,.5,.5);
                        DEFAULT_CHAT_FRAME:AddMessage(XLng["Chat"]["toggle_expf"],.5,.5,.5);
                        XAddonMngr_Toggle(nil);
                elseif (msg=="on" or msg=="an" or msg=="off" or msg=="aus") then XBar_Toggle();
                elseif (msg=="mm") or (msg=="main") then
                        if (MainMenuFrame:IsVisible()) then MainMenuFrame:Hide(); XBar["MM"]=true;
                        else MainMenuFrame:Show(); XBar["MM"]=false; end
                elseif (msg=="ef") or (msg=="exp") then
                        if (ExperienceFrame:IsVisible()) then ExperienceFrame:Hide(); XBar["EF"]=true;
                        else ExperienceFrame:Show(); XBar["EF"]=false; end
                end
end


function MinimapWheelZoom_OnLoad(this)
        g_minimapZooms = { 0.18, 0.28, 0.38, 0.49, 0.61, 0.74, 0.88, 1.03, 1.2, 1.38, 1.59, 1.82, 2.09, 2.4, 2.79, 3.2, 3.6, 4 }
end

local function ZoomOut()
        if ( g_MinimapDate.ZoomIndex > 1 ) then
                g_MinimapDate.ZoomIndex = g_MinimapDate.ZoomIndex - 1
                SetMiniMapZoomValue(g_minimapZooms[g_MinimapDate.ZoomIndex])
        end
end

local function ZoomIn()
        if ( g_MinimapDate.ZoomIndex < table.getn(g_minimapZooms) ) then
                g_MinimapDate.ZoomIndex = g_MinimapDate.ZoomIndex + 1
                SetMiniMapZoomValue(g_minimapZooms[g_MinimapDate.ZoomIndex])
        end
end

function MinimapZoomOverlayFrame_OnMouseWheel(this, delta)
        if ( delta < 0 ) then
                ZoomOut()
        else
                ZoomIn()
        end
end

OnClick_MinimapPlusButton = ZoomIn
OnClick_MinimapMinusButton = ZoomOut




-- #################################################################################################################
-- XBar III - New Features
-- #################################################################################################################



----------
-- MapFix
----------

function WorldMapFrame_SetWorldMapID( MapID )

        if( WorldMapFrame.mapID == MapID )then
                return;
        end

        ZoneName = GetZoneEnglishName( MapID );

        if( not ZoneName )then
                HideUIPanel( WorldMapFrame );
                return;
        end

        SetWorldMapID( MapID );
        WorldMapFrame.mapID = MapID;

        local imageLocation

        -- change image location to "rw" if it's a dungeon map
        ZoneName = ZoneName:lower()
        if ZoneName:find("dgn_") or ZoneName:find("dng_") then
                imageLocation = "rw"
        else
                imageLocation = GetImageLocation( "WORLDMAP" )
        end

        for i = 1,12 do
                local WorldMapTexture = getglobal( "WorldMapViewFrame_WorldMapTexture_" .. i );
                WorldMapTexture:SetFile( "\\Interface\\WorldMap\\" .. imageLocation .. "\\" .. ZoneName .. "\\" .. i );
        end

        ZoneName = GetZoneLocalName( WorldMapFrame.mapID );
        WorldMapSelectMapButton:SetText( ZoneName );

end


-- /run for i=1,50000 do local x = GetZoneEnglishName(i) if x then echo(i, x) end end


----------------------
-- RightClick-Checker
----------------------

local itemidfordon=0;

function BagRightclickChecker_OnLoad(this)
        this:RegisterEvent("VARIABLES_LOADED");
        this:RegisterEvent("PLAYER_BAG_CHANGED");
end;

StaticPopupDialogs["clo.to.don"] = {
        text = TEXT("Dieses Item wirklich anlegen?"),
        button1 = TEXT("ACCEPT"),
        button2 = TEXT("CANCEL"),
        OnAccept = function(this)
                UseBagItem(itemidfordon);
        end,
        hideOnEscape = 1
};

function BagItemButton_OnClick(this, button, ignoreShift)
        if ( button == "LBUTTON" ) then
                if( IsShiftKeyDown() ) then

                        local itemLink = GetBagItemLink( this.index );
                        if( ChatEdit_AddItemLink( itemLink ) )then
                                return;
                        end

                        local index, file, name, itemCount, locked = GetBagItemInfo(this:GetID());
                        itemCount = itemCount or 0;

                        if( locked or itemCount <= 1 )then
                                return;
                        end

                        this.AskNumberFrameCallBack = function( button , Number )
                                SplitBagItem( this.index , Number );
                        end

                        OpenAskNumberFrame( 1, itemCount, this, "BOTTOMRIGHT", "TOPRIGHT" );
                        return;
                elseif( IsCtrlKeyDown() ) then

                        local itemLink = GetBagItemLink( this.index );
                        ItemPreviewFrame_SetItemLink( ItemPreviewFrame, itemLink );

                        return;
                end
                PickupBagItem(this.index);

        elseif ( button == "RBUTTON" ) then
                if ( GarbageFrame:IsVisible() ) then
                        InsertGarbageItem(this.index);
                        return;
                end
                local line="";

                for i=2,6 do
                        if(_G["GameTooltipTextLeft"..i]:GetText() ~=nil) then
                                line = line .."  ".._G["GameTooltipTextLeft"..i]:GetText();
                        end
                end
                --DEFAULT_CHAT_FRAME:AddMessage(line, 1, 0.95, 0.40);
                if  ((  string.find(line, "Grad "))  and  ( string.find(line, "Stufe") )) then
                    -- Eqipment
                        if(StoreFrame:IsVisible() ) then
                                UseBagItem(this.index);
                        else
                            SystemMsgFrame:AddMessage("Kein H\195\164ndlerfenster offen", 1, 0.95, 0.40 );
                                itemidfordon = this.index;
                                StaticPopup_Show("clo.to.don");
                        end;

                elseif ((line==nil) or (line == "")) then
                        SystemMsgFrame:AddMessage("Tooltiptext konnte nicht ermittelt werden", 1, 0.95, 0.40 );
                        DEFAULT_CHAT_FRAME:AddMessage("Tooltiptext konnte nicht ermittelt werden", 1, 0.95, 0.40);
                else --kein Equipment
                        UseBagItem(this.index);

                end
        end  --( button == "RBUTTON" )


        AskNumberFrame:Hide();
end


---------------------
-- weitere Funktionen
---------------------

function wait(seconds)
  local start = os.time()
  repeat until os.time() > start + seconds
end

function switch1()
                SwapEquipmentItem();
                DEFAULT_CHAT_FRAME:AddMessage("XBar: Equiptment switched !");
end

function previewit()
        ItemPreviewFrame:Show();
        ItemPreviewFrame:SetSize(260*2, 350*2);
        ItemPreviewFrameModel:SetUnit("target", 1)
        DEFAULT_CHAT_FRAME:AddMessage("XBar: Ziel als Preview!");
end

function strip()
                EquipItem(16, GetBagItemInfo(57)); --
                EquipItem(17, GetBagItemInfo(58)); --
                EquipItem(1, GetBagItemInfo(56)); --
                EquipItem(2, GetBagItemInfo(55)); --
                EquipItem(3, GetBagItemInfo(54)); --
                EquipItem(4, GetBagItemInfo(53)); --
                EquipItem(5, GetBagItemInfo(52)); --
                EquipItem(6, GetBagItemInfo(51)); --
                EquipItem(7, GetBagItemInfo(50)); --
                EquipItem(8, GetBagItemInfo(49)); --
                EquipItem(9, GetBagItemInfo(48)); --
                EquipItem(11, GetBagItemInfo(60)); --
                EquipItem(12, GetBagItemInfo(46)); --
                EquipItem(13, GetBagItemInfo(45)); --
                EquipItem(14, GetBagItemInfo(44)); --
                EquipItem(15, GetBagItemInfo(47)); --
                DEFAULT_CHAT_FRAME:AddMessage("XBar: STRIP !     ... erneut wechseln zum Wiederherstellen.");
end

 function healgrp()
        TargetUnit("player");
        for a=1,GetNumPartyMembers()-1 do p="party"..a; t="target";
                if(UnitHealth(p)>1 and UnitHealth(p)/UnitMaxHealth(p) < UnitHealth(t)/UnitMaxHealth(t)) then
                        TargetUnit(p)
                end
        end
        CastSpellByName("Regeneration")
        DEFAULT_CHAT_FRAME:AddMessage("XBar: Panik-Heal ausgeführt !");
end

function Testfunction1()
        SendWarningMsg("Warning Message !!!")
        SendChatMessage("  rom.suchtis.de ROXX   ", "ZONE");
        DEFAULT_CHAT_FRAME:AddMessage("XBar: Testfunktion 1 ausgeführt !");
end

function Testfunction2()
        SendWarningMsg("Warning Message !!!");
        DEFAULT_CHAT_FRAME:AddMessage("XBar: Testfunktion 2 ausgeführt !");
end

function switch101()
                EquipItem(16, GetBagItemInfo(57)); -- HaupthandSwitch
                EquipItem(17, GetBagItemInfo(58)); -- Nebenhand
                EquipItem(11, GetBagItemInfo(60)); -- BogenSwitch
                wait(0.5);
                SwapEquipmentItem();
                wait(1.5);
                EquipItem(16, GetBagItemInfo(57)); -- HaupthandSwitch
                EquipItem(17, GetBagItemInfo(58)); -- Nebenhand
                EquipItem(11, GetBagItemInfo(60)); -- BogenSwitch
                DEFAULT_CHAT_FRAME:AddMessage("XBar: Angel-Switch beendet.");
end

function SendWarningMsg( text )
        PlaySoundByPath("sound\\interface\\ui_sysmsg_warning.mp3");
        WarningFrame:AddMessage(text, 0.93, 0.11, 0.14);
end

function MacroInfo()
        DEFAULT_CHAT_FRAME:AddMessage("XBar: Available Commands (macro or chat)");
        DEFAULT_CHAT_FRAME:AddMessage("/run switch101() : switch weapons to other equipt");
        DEFAULT_CHAT_FRAME:AddMessage("/run healgrp() : search fpr lowest hp in group and reg");
        DEFAULT_CHAT_FRAME:AddMessage("/run strip() : unequipt all items to 2nd page inv");
        DEFAULT_CHAT_FRAME:AddMessage("/run switch1() : switch equiptment 1/2");
        DEFAULT_CHAT_FRAME:AddMessage("/adBA : triggers a siple GUI to change the BottomArt.");
        DEFAULT_CHAT_FRAME:AddMessage("/adBA show : shows the BottomArt");
        DEFAULT_CHAT_FRAME:AddMessage("/adBA hide : hides the BottomArt");
        DEFAULT_CHAT_FRAME:AddMessage("/adBA skin XXXX : loads a texture pack called XXXX");
end


